From f6aad5ed2d0a492f968269a0948ddb782e400c8e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 27 Jul 2015 16:00:39 +0530 Subject: [PATCH] Distribute tax amount between items in stock entry --- .../doctype/stock_entry/stock_entry.json | 29 ++++++++++- .../stock/doctype/stock_entry/stock_entry.py | 48 +++++++++++-------- .../stock_entry_detail.json | 9 +++- 3 files changed, 64 insertions(+), 22 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.json b/erpnext/stock/doctype/stock_entry/stock_entry.json index 3c39d42ff6..f2ea6d4dc2 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.json +++ b/erpnext/stock/doctype/stock_entry/stock_entry.json @@ -369,6 +369,7 @@ "fieldname": "total_incoming_value", "fieldtype": "Currency", "label": "Total Incoming Value", + "options": "Company:company:default_currency", "permlevel": 0, "precision": "", "read_only": 1 @@ -383,6 +384,7 @@ "fieldname": "total_outgoing_value", "fieldtype": "Currency", "label": "Total Outgoing Value", + "options": "Company:company:default_currency", "permlevel": 0, "precision": "", "read_only": 1 @@ -391,6 +393,7 @@ "fieldname": "value_difference", "fieldtype": "Currency", "label": "Total Value Difference (Out - In)", + "options": "Company:company:default_currency", "permlevel": 0, "precision": "", "read_only": 1 @@ -404,6 +407,30 @@ "permlevel": 0, "precision": "" }, + { + "fieldname": "taxes_section", + "fieldtype": "Section Break", + "label": "Taxes and Charges", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "taxes", + "fieldtype": "Table", + "label": "Taxes and Charges", + "options": "Landed Cost Taxes and Charges", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "total_taxes_and_charges", + "fieldtype": "Currency", + "label": "Total Taxes and Charges", + "options": "Company:company:default_currency", + "permlevel": 0, + "precision": "", + "read_only": 1 + }, { "fieldname": "fold", "fieldtype": "Fold", @@ -678,7 +705,7 @@ "is_submittable": 1, "issingle": 0, "max_attachments": 0, - "modified": "2015-07-22 18:47:20.328749", + "modified": "2015-07-24 18:47:55.902154", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry", diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 61ef4cdefc..06249edbc1 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -50,6 +50,7 @@ class StockEntry(StockController): self.validate_bom() self.validate_finished_goods() self.validate_with_material_request() + self.distribute_taxes() self.validate_valuation_rate() self.set_total_incoming_outgoing_value() self.set_total_amount() @@ -221,7 +222,7 @@ class StockEntry(StockController): if d.s_warehouse and not d.t_warehouse: valuation_at_source += flt(d.amount) if d.t_warehouse and not d.s_warehouse: - valuation_at_target += flt(d.amount) + valuation_at_target += flt(d.amount) + flt(d.tax_amount) if valuation_at_target + 0.001 < valuation_at_source: frappe.throw(_("Total valuation ({0}) for manufactured or repacked item(s) can not be less than total valuation of raw materials ({1})").format(valuation_at_target, @@ -230,10 +231,10 @@ class StockEntry(StockController): def set_total_incoming_outgoing_value(self): self.total_incoming_value = self.total_outgoing_value = 0.0 for d in self.get("items"): - if d.s_warehouse: - self.total_incoming_value += flt(d.amount) if d.t_warehouse: - self.total_outgoing_value += flt(d.amount) + self.total_incoming_value += flt(d.amount) + if d.s_warehouse: + self.total_outgoing_value += flt(d.amount) + flt(d.tax_amount) self.value_difference = self.total_outgoing_value - self.total_incoming_value @@ -316,7 +317,7 @@ class StockEntry(StockController): bom = frappe.db.get_value("BOM", bom_no, ["operating_cost", "quantity"], as_dict=1) operation_cost_per_unit = flt(bom.operating_cost) / flt(bom.quantity) - return operation_cost_per_unit + (flt(self.additional_operating_cost) / flt(qty)) + return operation_cost_per_unit def validate_purchase_order(self): """Throw exception if more raw material is transferred against Purchase Order than in @@ -402,22 +403,23 @@ class StockEntry(StockController): for d in self.get("items"): tax_amount = flt(d.tax_amount, d.precision("tax_amount")) - gl_entries.append(self.get_gl_dict({ - "account": d.expense_account, - "against": expenses_included_in_valuation, - "cost_center": d.cost_center, - "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "debit": tax_amount - })) - - gl_entries.append(self.get_gl_dict({ - "account": expenses_included_in_valuation, - "against": warehouse_account[d.warehouse], - "cost_center": d.cost_center, - "remarks": self.get("remarks") or _("Accounting Entry for Stock"), - "credit": tax_amount - })) + if tax_amount: + gl_entries.append(self.get_gl_dict({ + "account": expenses_included_in_valuation, + "against": d.expense_account, + "cost_center": d.cost_center, + "remarks": self.get("remarks") or _("Accounting Entry for Stock"), + "credit": tax_amount + })) + gl_entries.append(self.get_gl_dict({ + "account": d.expense_account, + "against": expenses_included_in_valuation, + "cost_center": d.cost_center, + "remarks": self.get("remarks") or _("Accounting Entry for Stock"), + "credit": -1 * tax_amount + })) + return gl_entries def update_production_order(self): @@ -693,6 +695,12 @@ class StockEntry(StockController): if expiry_date: if getdate(self.posting_date) > getdate(expiry_date): frappe.throw(_("Batch {0} of Item {1} has expired.").format(item.batch_no, item.item_code)) + + def distribute_taxes(self): + self.total_taxes_and_charges = sum([flt(t.amount) for t in self.get("taxes")]) + for d in self.get("items"): + if d.t_warehouse and self.total_incoming_value: + d.tax_amount = (flt(d.amount) / flt(self.total_incoming_value)) * self.total_taxes_and_charges @frappe.whitelist() diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json index a373185c23..dcd46bd51f 100644 --- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json +++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json @@ -160,6 +160,13 @@ "permlevel": 0, "read_only": 1 }, + { + "fieldname": "tax_amount", + "fieldtype": "Currency", + "label": "Tax Amount", + "permlevel": 0, + "precision": "" + }, { "fieldname": "col_break3", "fieldtype": "Column Break", @@ -344,7 +351,7 @@ ], "idx": 1, "istable": 1, - "modified": "2015-07-02 05:32:56.511570", + "modified": "2015-07-24 17:03:44.214018", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry Detail",