fix: Add distribute manually option in LCV

This commit is contained in:
Deepesh Garg 2021-01-26 17:05:00 +05:30
parent 224fdf34e4
commit a0d61524c1
6 changed files with 133 additions and 50 deletions

View File

@ -1,4 +1,5 @@
{ {
"actions": [],
"creation": "2013-02-22 01:28:02", "creation": "2013-02-22 01:28:02",
"doctype": "DocType", "doctype": "DocType",
"document_type": "Document", "document_type": "Document",
@ -29,6 +30,8 @@
"options": "Item", "options": "Item",
"read_only": 1, "read_only": 1,
"reqd": 1, "reqd": 1,
"show_days": 1,
"show_seconds": 1,
"width": "100px" "width": "100px"
}, },
{ {
@ -41,6 +44,8 @@
"print_width": "300px", "print_width": "300px",
"read_only": 1, "read_only": 1,
"reqd": 1, "reqd": 1,
"show_days": 1,
"show_seconds": 1,
"width": "120px" "width": "120px"
}, },
{ {
@ -50,7 +55,9 @@
"no_copy": 1, "no_copy": 1,
"options": "Purchase Invoice\nPurchase Receipt", "options": "Purchase Invoice\nPurchase Receipt",
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "receipt_document", "fieldname": "receipt_document",
@ -59,25 +66,33 @@
"no_copy": 1, "no_copy": 1,
"options": "receipt_document_type", "options": "receipt_document_type",
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "col_break2", "fieldname": "col_break2",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "qty", "fieldname": "qty",
"fieldtype": "Float", "fieldtype": "Float",
"in_list_view": 1, "in_list_view": 1,
"label": "Qty", "label": "Qty",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "rate", "fieldname": "rate",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Rate", "label": "Rate",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "amount", "fieldname": "amount",
@ -88,14 +103,19 @@
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1, "read_only": 1,
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "applicable_charges", "fieldname": "applicable_charges",
"fieldtype": "Currency", "fieldtype": "Currency",
"in_list_view": 1, "in_list_view": 1,
"label": "Applicable Charges", "label": "Applicable Charges",
"options": "Company:company:default_currency" "options": "Company:company:default_currency",
"read_only_depends_on": "eval:parent.distribute_charges_based_on != 'Distribute Manually'",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "purchase_receipt_item", "fieldname": "purchase_receipt_item",
@ -104,22 +124,30 @@
"label": "Purchase Receipt Item", "label": "Purchase Receipt Item",
"no_copy": 1, "no_copy": 1,
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "cost_center", "fieldname": "cost_center",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Cost Center", "label": "Cost Center",
"options": "Cost Center" "options": "Cost Center",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "accounting_dimensions_section", "fieldname": "accounting_dimensions_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Accounting Dimensions" "label": "Accounting Dimensions",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "dimension_col_break", "fieldname": "dimension_col_break",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"default": "0", "default": "0",
@ -128,12 +156,15 @@
"fieldtype": "Check", "fieldtype": "Check",
"hidden": 1, "hidden": 1,
"label": "Is Fixed Asset", "label": "Is Fixed Asset",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
} }
], ],
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"modified": "2020-09-18 17:26:09.703215", "links": [],
"modified": "2021-01-25 23:09:23.322282",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Landed Cost Item", "name": "Landed Cost Item",

View File

@ -101,25 +101,27 @@ erpnext.stock.LandedCostVoucher = erpnext.stock.StockController.extend({
var me = this; var me = this;
if(this.frm.doc.taxes.length) { if(this.frm.doc.taxes.length) {
var total_item_cost = 0.0; var total_item_cost = 0.0;
var based_on = this.frm.doc.distribute_charges_based_on.toLowerCase(); var based_on = this.frm.doc.distribute_charges_based_on.toLowerCase();
$.each(this.frm.doc.items || [], function(i, d) {
total_item_cost += flt(d[based_on])
});
var total_charges = 0.0; if (based_on != 'distribute manually') {
$.each(this.frm.doc.items || [], function(i, item) { $.each(this.frm.doc.items || [], function(i, d) {
item.applicable_charges = flt(item[based_on]) * flt(me.frm.doc.total_taxes_and_charges) / flt(total_item_cost) total_item_cost += flt(d[based_on])
item.applicable_charges = flt(item.applicable_charges, precision("applicable_charges", item)) });
total_charges += item.applicable_charges
});
if (total_charges != this.frm.doc.total_taxes_and_charges){ var total_charges = 0.0;
var diff = this.frm.doc.total_taxes_and_charges - flt(total_charges) $.each(this.frm.doc.items || [], function(i, item) {
this.frm.doc.items.slice(-1)[0].applicable_charges += diff item.applicable_charges = flt(item[based_on]) * flt(me.frm.doc.total_taxes_and_charges) / flt(total_item_cost)
item.applicable_charges = flt(item.applicable_charges, precision("applicable_charges", item))
total_charges += item.applicable_charges
});
if (total_charges != this.frm.doc.total_taxes_and_charges){
var diff = this.frm.doc.total_taxes_and_charges - flt(total_charges)
this.frm.doc.items.slice(-1)[0].applicable_charges += diff
}
refresh_field("items");
} }
refresh_field("items");
} }
}, },
distribute_charges_based_on: function (frm) { distribute_charges_based_on: function (frm) {

View File

@ -34,7 +34,9 @@
"options": "MAT-LCV-.YYYY.-", "options": "MAT-LCV-.YYYY.-",
"print_hide": 1, "print_hide": 1,
"reqd": 1, "reqd": 1,
"set_only_once": 1 "set_only_once": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "company", "fieldname": "company",
@ -44,24 +46,32 @@
"label": "Company", "label": "Company",
"options": "Company", "options": "Company",
"remember_last_selected_value": 1, "remember_last_selected_value": 1,
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "purchase_receipts", "fieldname": "purchase_receipts",
"fieldtype": "Table", "fieldtype": "Table",
"label": "Purchase Receipts", "label": "Purchase Receipts",
"options": "Landed Cost Purchase Receipt", "options": "Landed Cost Purchase Receipt",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "purchase_receipt_items", "fieldname": "purchase_receipt_items",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Purchase Receipt Items" "label": "Purchase Receipt Items",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "get_items_from_purchase_receipts", "fieldname": "get_items_from_purchase_receipts",
"fieldtype": "Button", "fieldtype": "Button",
"label": "Get Items From Purchase Receipts" "label": "Get Items From Purchase Receipts",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "items", "fieldname": "items",
@ -69,23 +79,31 @@
"label": "Purchase Receipt Items", "label": "Purchase Receipt Items",
"no_copy": 1, "no_copy": 1,
"options": "Landed Cost Item", "options": "Landed Cost Item",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "sec_break1", "fieldname": "sec_break1",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Applicable Charges" "label": "Applicable Charges",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "taxes", "fieldname": "taxes",
"fieldtype": "Table", "fieldtype": "Table",
"label": "Taxes and Charges", "label": "Taxes and Charges",
"options": "Landed Cost Taxes and Charges", "options": "Landed Cost Taxes and Charges",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "section_break_9", "fieldname": "section_break_9",
"fieldtype": "Section Break" "fieldtype": "Section Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "total_taxes_and_charges", "fieldname": "total_taxes_and_charges",
@ -93,18 +111,24 @@
"label": "Total Taxes and Charges (Company Currency)", "label": "Total Taxes and Charges (Company Currency)",
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"read_only": 1, "read_only": 1,
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "col_break1", "fieldname": "col_break1",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "distribute_charges_based_on", "fieldname": "distribute_charges_based_on",
"fieldtype": "Select", "fieldtype": "Select",
"label": "Distribute Charges Based On", "label": "Distribute Charges Based On",
"options": "Qty\nAmount", "options": "Qty\nAmount\nDistribute Manually",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "amended_from", "fieldname": "amended_from",
@ -113,39 +137,51 @@
"no_copy": 1, "no_copy": 1,
"options": "Landed Cost Voucher", "options": "Landed Cost Voucher",
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "sec_break2", "fieldname": "sec_break2",
"fieldtype": "Section Break" "fieldtype": "Section Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "landed_cost_help", "fieldname": "landed_cost_help",
"fieldtype": "HTML", "fieldtype": "HTML",
"label": "Landed Cost Help" "label": "Landed Cost Help",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "column_break_2", "fieldname": "column_break_2",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"default": "Today", "default": "Today",
"fieldname": "posting_date", "fieldname": "posting_date",
"fieldtype": "Date", "fieldtype": "Date",
"label": "Posting Date", "label": "Posting Date",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "section_break_5", "fieldname": "section_break_5",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hide_border": 1 "hide_border": 1,
"show_days": 1,
"show_seconds": 1
} }
], ],
"icon": "icon-usd", "icon": "icon-usd",
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2020-12-13 23:18:47.442466", "modified": "2021-01-25 23:07:30.468423",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Landed Cost Voucher", "name": "Landed Cost Voucher",

View File

@ -80,7 +80,7 @@ class LandedCostVoucher(Document):
self.total_taxes_and_charges = sum([flt(d.base_amount) for d in self.get("taxes")]) self.total_taxes_and_charges = sum([flt(d.base_amount) for d in self.get("taxes")])
def set_applicable_charges_on_item(self): def set_applicable_charges_on_item(self):
if self.get('taxes'): if self.get('taxes') and self.distribute_charges_based_on != 'Distribute Manually':
total_item_cost = 0.0 total_item_cost = 0.0
total_charges = 0.0 total_charges = 0.0
item_count = 0 item_count = 0
@ -102,7 +102,11 @@ class LandedCostVoucher(Document):
def validate_applicable_charges_for_item(self): def validate_applicable_charges_for_item(self):
based_on = self.distribute_charges_based_on.lower() based_on = self.distribute_charges_based_on.lower()
total = sum([flt(d.get(based_on)) for d in self.get("items")]) if based_on != 'distribute manually':
total = sum([flt(d.get(based_on)) for d in self.get("items")])
else:
# consider for proportion while distributing manually
total = sum([flt(d.get('applicable_charges')) for d in self.get("items")])
if not total: if not total:
frappe.throw(_("Total {0} for all items is zero, may be you should change 'Distribute Charges Based On'").format(based_on)) frappe.throw(_("Total {0} for all items is zero, may be you should change 'Distribute Charges Based On'").format(based_on))

View File

@ -731,7 +731,13 @@ def get_item_account_wise_additional_cost(purchase_document):
for lcv in landed_cost_vouchers: for lcv in landed_cost_vouchers:
landed_cost_voucher_doc = frappe.get_doc("Landed Cost Voucher", lcv.parent) landed_cost_voucher_doc = frappe.get_doc("Landed Cost Voucher", lcv.parent)
based_on_field = frappe.scrub(landed_cost_voucher_doc.distribute_charges_based_on)
#Use amount field for total item cost for manually cost distributed LCVs
if landed_cost_voucher_doc.distribute_charges_based_on == 'Distribute Manually':
based_on_field = 'amount'
else:
based_on_field = frappe.scrub(landed_cost_voucher_doc.distribute_charges_based_on)
total_item_cost = 0 total_item_cost = 0
for item in landed_cost_voucher_doc.items: for item in landed_cost_voucher_doc.items:

View File

@ -30,7 +30,9 @@ document_list.forEach((doctype) => {
if (row.account_currency == company_currency) { if (row.account_currency == company_currency) {
row.exchange_rate = 1; row.exchange_rate = 1;
frm.set_df_property('taxes', 'hidden', 1, row.name, 'exchange_rate');
} else if (!row.exchange_rate || row.exchange_rate == 1) { } else if (!row.exchange_rate || row.exchange_rate == 1) {
frm.set_df_property('taxes', 'hidden', 0, row.name, 'exchange_rate');
frappe.call({ frappe.call({
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_exchange_rate", method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_exchange_rate",
args: { args: {
@ -46,6 +48,8 @@ document_list.forEach((doctype) => {
} }
}); });
} }
frm.refresh_field('taxes');
}, },
set_base_amount: function(frm, cdt, cdn) { set_base_amount: function(frm, cdt, cdn) {