Skip to content

Commit

Permalink
Merge pull request #3823 from nabinhait/stock-entry-tax
Browse files Browse the repository at this point in the history
Stock entry tax
  • Loading branch information
rmehta committed Aug 10, 2015
2 parents 47b5e62 + 52f3bfc commit 6f59313
Show file tree
Hide file tree
Showing 23 changed files with 1,459 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ def test_invoice_due_date_against_customers_credit_days(self):
def test_return_sales_invoice(self):
set_perpetual_inventory()

make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, incoming_rate=100)
make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, basic_rate=100)

actual_qty_0 = get_qty_after_transaction()

Expand Down
3 changes: 1 addition & 2 deletions erpnext/accounts/general_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

class StockAccountInvalidTransaction(frappe.ValidationError): pass

def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True,
update_outstanding='Yes'):
def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True, update_outstanding='Yes'):
if gl_map:
if not cancel:
gl_map = process_gl_map(gl_map, merge_entries)
Expand Down
2 changes: 2 additions & 0 deletions erpnext/buying/doctype/supplier/supplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ cur_frm.cscript.make_dashboard = function(doc) {
+ '</b> / <span class="text-muted">' + __("Total Unpaid") + ": <b>"
+ format_currency(r.message.total_unpaid, r.message.company_currency[0])
+ '</b></span>');
} else {
cur_frm.dashboard.set_headline("");
}
}
cur_frm.dashboard.set_badge_count(r.message);
Expand Down
2 changes: 2 additions & 0 deletions erpnext/change_log/current/stock_entry_additional_costs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Additional Costs in Stock Entry **[Sponsored by PT. Ridho Sribumi Sejahtera]**
- Now additional costs like shipping charges, operating costs etc can be added in Stock Entry in item valuation
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
from dateutil.relativedelta import relativedelta
from erpnext.stock.doctype.item.item import validate_end_of_life
from erpnext.manufacturing.doctype.workstation.workstation import WorkstationHolidayError, NotInWorkingHoursError
from erpnext.projects.doctype.time_log.time_log import OverlapError
from erpnext.stock.doctype.stock_entry.stock_entry import get_additional_costs

class OverProductionError(frappe.ValidationError): pass
class StockOverProductionError(frappe.ValidationError): pass
class OperationTooLongError(frappe.ValidationError): pass
class ProductionNotApplicableError(frappe.ValidationError): pass
class ItemHasVariantError(frappe.ValidationError): pass

from erpnext.manufacturing.doctype.workstation.workstation import WorkstationHolidayError, NotInWorkingHoursError
from erpnext.projects.doctype.time_log.time_log import OverlapError

form_grid_templates = {
"operations": "templates/form_grid/production_order_grid.html"
}
Expand Down Expand Up @@ -356,7 +356,6 @@ def make_stock_entry(production_order_id, purpose, qty=None):
stock_entry.company = production_order.company
stock_entry.from_bom = 1
stock_entry.bom_no = production_order.bom_no
stock_entry.additional_operating_cost = production_order.additional_operating_cost
stock_entry.use_multi_level_bom = production_order.use_multi_level_bom
stock_entry.fg_completed_qty = qty or (flt(production_order.qty) - flt(production_order.produced_qty))

Expand All @@ -365,6 +364,8 @@ def make_stock_entry(production_order_id, purpose, qty=None):
else:
stock_entry.from_warehouse = production_order.wip_warehouse
stock_entry.to_warehouse = production_order.fg_warehouse
additional_costs = get_additional_costs(production_order, fg_qty=stock_entry.fg_completed_qty)
stock_entry.set("additional_costs", additional_costs)

stock_entry.get_items()
return stock_entry.as_dict()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def check_planned_qty(self):

# add raw materials to stores
test_stock_entry.make_stock_entry(item_code="_Test Item",
target="Stores - _TC", qty=100, incoming_rate=100)
target="Stores - _TC", qty=100, basic_rate=100)
test_stock_entry.make_stock_entry(item_code="_Test Item Home Desktop 100",
target="Stores - _TC", qty=100, incoming_rate=100)
target="Stores - _TC", qty=100, basic_rate=100)

# from stores to wip
s = frappe.get_doc(make_stock_entry(pro_order.name, "Material Transfer for Manufacture", 4))
Expand Down Expand Up @@ -58,9 +58,9 @@ def test_over_production(self):
pro_doc = self.check_planned_qty()

test_stock_entry.make_stock_entry(item_code="_Test Item",
target="_Test Warehouse - _TC", qty=100, incoming_rate=100)
target="_Test Warehouse - _TC", qty=100, basic_rate=100)
test_stock_entry.make_stock_entry(item_code="_Test Item Home Desktop 100",
target="_Test Warehouse - _TC", qty=100, incoming_rate=100)
target="_Test Warehouse - _TC", qty=100, basic_rate=100)

s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture", 7))
s.insert()
Expand Down
1 change: 1 addition & 0 deletions erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,4 @@ erpnext.patches.v5_4.notify_system_managers_regarding_wrong_tax_calculation
erpnext.patches.v5_4.fix_invoice_outstanding
execute:frappe.db.sql("update `tabStock Ledger Entry` set stock_queue = '[]' where voucher_type = 'Stock Reconciliation' and ifnull(qty_after_transaction, 0) = 0")
erpnext.patches.v5_4.fix_missing_item_images
erpnext.patches.v5_4.stock_entry_additional_costs
42 changes: 42 additions & 0 deletions erpnext/patches/v5_4/stock_entry_additional_costs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2015, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt

from __future__ import unicode_literals
import frappe
from frappe.utils import flt

def execute():
frappe.reload_doctype("Stock Entry")
frappe.reload_doctype("Stock Entry Detail")
frappe.reload_doctype("Landed Cost Taxes and Charges")

frappe.db.sql("""update `tabStock Entry Detail` sed, `tabStock Entry` se
set sed.valuation_rate=sed.incoming_rate, sed.basic_rate=sed.incoming_rate, sed.basic_amount=sed.amount
where sed.parent = se.name
and (se.purpose not in ('Manufacture', 'Repack') or ifnull(additional_operating_cost, 0)=0)
""")

stock_entries = frappe.db.sql_list("""select name from `tabStock Entry`
where purpose in ('Manufacture', 'Repack') and ifnull(additional_operating_cost, 0)!=0""")

for d in stock_entries:
stock_entry = frappe.get_doc("Stock Entry", d)
stock_entry.append("additional_costs", {
"description": "Additional Operating Cost",
"amount": stock_entry.additional_operating_cost
})

number_of_fg_items = len([t.t_warehouse for t in stock_entry.get("items") if t.t_warehouse])

for d in stock_entry.get("items"):
d.valuation_rate = d.incoming_rate

if d.bom_no or (d.t_warehouse and number_of_fg_items == 1):
d.additional_cost = stock_entry.additional_operating_cost

d.basic_rate = flt(d.valuation_rate) - flt(d.additional_cost)
d.basic_amount = flt(flt(d.basic_rate) *flt(d.transfer_qty), d.precision("basic_amount"))

stock_entry.flags.ignore_validate = True
stock_entry.flags.ignore_validate_update_after_submit = True
stock_entry.save()
12 changes: 6 additions & 6 deletions erpnext/stock/doctype/delivery_note/test_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_delivery_note_no_gl_entry(self):
set_perpetual_inventory(0)
self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 0)

make_stock_entry(target="_Test Warehouse - _TC", qty=5, incoming_rate=100)
make_stock_entry(target="_Test Warehouse - _TC", qty=5, basic_rate=100)

stock_queue = json.loads(get_previous_sle({
"item_code": "_Test Item",
Expand All @@ -59,7 +59,7 @@ def test_delivery_note_gl_entry(self):
self.assertEqual(cint(frappe.defaults.get_global_default("auto_accounting_for_stock")), 1)
frappe.db.set_value("Item", "_Test Item", "valuation_method", "FIFO")

make_stock_entry(target="_Test Warehouse - _TC", qty=5, incoming_rate=100)
make_stock_entry(target="_Test Warehouse - _TC", qty=5, basic_rate=100)

stock_in_hand_account = frappe.db.get_value("Account", {"warehouse": "_Test Warehouse - _TC"})
prev_bal = get_balance_on(stock_in_hand_account)
Expand All @@ -85,7 +85,7 @@ def test_delivery_note_gl_entry(self):

# back dated incoming entry
make_stock_entry(posting_date=add_days(nowdate(), -2), target="_Test Warehouse - _TC",
qty=5, incoming_rate=100)
qty=5, basic_rate=100)

gl_entries = get_gl_entries("Delivery Note", dn.name)
self.assertTrue(gl_entries)
Expand All @@ -107,9 +107,9 @@ def test_delivery_note_gl_entry(self):
def test_delivery_note_gl_entry_packing_item(self):
set_perpetual_inventory()

make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=10, incoming_rate=100)
make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=10, basic_rate=100)
make_stock_entry(item_code="_Test Item Home Desktop 100",
target="_Test Warehouse - _TC", qty=10, incoming_rate=100)
target="_Test Warehouse - _TC", qty=10, basic_rate=100)

stock_in_hand_account = frappe.db.get_value("Account", {"warehouse": "_Test Warehouse - _TC"})
prev_bal = get_balance_on(stock_in_hand_account)
Expand Down Expand Up @@ -184,7 +184,7 @@ def check_serial_no_values(self, serial_no, field_values):
def test_sales_return_for_non_bundled_items(self):
set_perpetual_inventory()

make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, incoming_rate=100)
make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, basic_rate=100)

actual_qty_0 = get_qty_after_transaction()

Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/doctype/item/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_item(self, idx):

def test_template_cannot_have_stock(self):
item = self.get_item(10)
make_stock_entry(item_code=item.name, target="Stores - _TC", qty=1, incoming_rate=1)
make_stock_entry(item_code=item.name, target="Stores - _TC", qty=1, basic_rate=1)
item.has_variants = 1
self.assertRaises(ItemTemplateCannotHaveStock, item.save)

Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/doctype/material_request/material_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def update_item(obj, target, source_parent):

def set_missing_values(source, target):
target.purpose = source.material_request_type
target.run_method("get_stock_and_rate")
target.run_method("calculate_rate_and_amount")

doclist = get_mapped_doc("Material Request", source_name, {
"Material Request": {
Expand Down
16 changes: 8 additions & 8 deletions erpnext/stock/doctype/material_request/test_material_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _insert_stock_entry(self, qty1, qty2, warehouse = None ):
"doctype": "Stock Entry Detail",
"item_code": "_Test Item Home Desktop 100",
"parentfield": "items",
"incoming_rate": 100,
"basic_rate": 100,
"qty": qty1,
"stock_uom": "_Test UOM 1",
"transfer_qty": qty1,
Expand All @@ -84,7 +84,7 @@ def _insert_stock_entry(self, qty1, qty2, warehouse = None ):
"doctype": "Stock Entry Detail",
"item_code": "_Test Item Home Desktop 200",
"parentfield": "items",
"incoming_rate": 100,
"basic_rate": 100,
"qty": qty2,
"stock_uom": "_Test UOM 1",
"transfer_qty": qty2,
Expand Down Expand Up @@ -196,13 +196,13 @@ def test_completed_qty_for_transfer(self):
"qty": 27.0,
"transfer_qty": 27.0,
"s_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0
"basic_rate": 1.0
})
se_doc.get("items")[1].update({
"qty": 1.5,
"transfer_qty": 1.5,
"s_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0
"basic_rate": 1.0
})

# make available the qty in _Test Warehouse 1 before transfer
Expand Down Expand Up @@ -279,13 +279,13 @@ def test_completed_qty_for_over_transfer(self):
"qty": 60.0,
"transfer_qty": 60.0,
"s_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0
"basic_rate": 1.0
})
se_doc.get("items")[1].update({
"qty": 3.0,
"transfer_qty": 3.0,
"s_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0
"basic_rate": 1.0
})

# make available the qty in _Test Warehouse 1 before transfer
Expand Down Expand Up @@ -350,13 +350,13 @@ def test_incorrect_mapping_of_stock_entry(self):
"transfer_qty": 60.0,
"s_warehouse": "_Test Warehouse - _TC",
"t_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0
"basic_rate": 1.0
})
se_doc.get("items")[1].update({
"qty": 3.0,
"transfer_qty": 3.0,
"s_warehouse": "_Test Warehouse 1 - _TC",
"incoming_rate": 1.0
"basic_rate": 1.0
})

# check for stopped status of Material Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def test_purchase_receipt_gl_entry(self):
def test_subcontracting(self):
from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry

make_stock_entry(item_code="_Test Item", target="_Test Warehouse 1 - _TC", qty=100, incoming_rate=100)
make_stock_entry(item_code="_Test Item", target="_Test Warehouse 1 - _TC", qty=100, basic_rate=100)
make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse 1 - _TC",
qty=100, incoming_rate=100)
qty=100, basic_rate=100)

pr = make_purchase_receipt(item_code="_Test FG Item", qty=10, rate=500, is_subcontracted="Yes")
self.assertEquals(len(pr.get("supplied_items")), 2)
Expand Down
Loading

0 comments on commit 6f59313

Please sign in to comment.