feat: capture Rate of stock UOM in purchase (#24315)

* feat: capture Rate of stock UOM in purchase

* fix: review changes

* added server side code

* added stock uom rate in sales transactions

* fix: review changes

* fix: resolving conflicts

* adding patch

* fix: removing patch
This commit is contained in:
Anupam Kumar 2021-02-11 20:19:30 +05:30 committed by Nabin Hait
parent 4cef0f5983
commit b1997da488
10 changed files with 86 additions and 11 deletions

View File

@ -40,6 +40,7 @@
"base_rate", "base_rate",
"base_amount", "base_amount",
"pricing_rules", "pricing_rules",
"stock_uom_rate",
"is_free_item", "is_free_item",
"section_break_22", "section_break_22",
"net_rate", "net_rate",
@ -783,6 +784,14 @@
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1
}, },
{
"depends_on": "eval: doc.uom != doc.stock_uom",
"fieldname": "stock_uom_rate",
"fieldtype": "Currency",
"label": "Rate of Stock UOM",
"options": "currency",
"read_only": 1
},
{ {
"fieldname": "sales_invoice_item", "fieldname": "sales_invoice_item",
"fieldtype": "Data", "fieldtype": "Data",
@ -795,7 +804,7 @@
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2020-12-26 17:20:36.415791", "modified": "2021-01-30 21:43:21.488258",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Purchase Invoice Item", "name": "Purchase Invoice Item",

View File

@ -45,6 +45,7 @@
"base_rate", "base_rate",
"base_amount", "base_amount",
"pricing_rules", "pricing_rules",
"stock_uom_rate",
"is_free_item", "is_free_item",
"section_break_21", "section_break_21",
"net_rate", "net_rate",
@ -811,12 +812,20 @@
"no_copy": 1, "no_copy": 1,
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1
},
{
"depends_on": "eval: doc.uom != doc.stock_uom",
"fieldname": "stock_uom_rate",
"fieldtype": "Currency",
"label": "Rate of Stock UOM",
"options": "currency",
"read_only": 1
} }
], ],
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2020-12-26 17:25:04.090630", "modified": "2021-01-30 21:42:37.796771",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Sales Invoice Item", "name": "Sales Invoice Item",

View File

@ -40,6 +40,7 @@
"base_rate", "base_rate",
"base_amount", "base_amount",
"pricing_rules", "pricing_rules",
"stock_uom_rate",
"is_free_item", "is_free_item",
"section_break_29", "section_break_29",
"net_rate", "net_rate",
@ -726,13 +727,21 @@
"fieldname": "more_info_section_break", "fieldname": "more_info_section_break",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "More Information" "label": "More Information"
},
{
"depends_on": "eval: doc.uom != doc.stock_uom",
"fieldname": "stock_uom_rate",
"fieldtype": "Currency",
"label": "Rate of Stock UOM",
"options": "currency",
"read_only": 1
} }
], ],
"idx": 1, "idx": 1,
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2020-12-07 11:59:47.670951", "modified": "2021-01-30 21:44:41.816974",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Buying", "module": "Buying",
"name": "Purchase Order Item", "name": "Purchase Order Item",

View File

@ -24,6 +24,7 @@ class StockController(AccountsController):
self.validate_inspection() self.validate_inspection()
self.validate_serialized_batch() self.validate_serialized_batch()
self.validate_customer_provided_item() self.validate_customer_provided_item()
self.set_rate_of_stock_uom()
self.validate_internal_transfer() self.validate_internal_transfer()
self.validate_putaway_capacity() self.validate_putaway_capacity()
@ -395,6 +396,11 @@ class StockController(AccountsController):
if frappe.db.get_value('Item', d.item_code, 'is_customer_provided_item'): if frappe.db.get_value('Item', d.item_code, 'is_customer_provided_item'):
d.allow_zero_valuation_rate = 1 d.allow_zero_valuation_rate = 1
def set_rate_of_stock_uom(self):
if self.doctype in ["Purchase Receipt", "Purchase Invoice", "Purchase Order", "Sales Invoice", "Sales Order", "Delivery Note", "Quotation"]:
for d in self.get("items"):
d.stock_uom_rate = d.rate / d.conversion_factor
def validate_internal_transfer(self): def validate_internal_transfer(self):
if self.doctype in ('Sales Invoice', 'Delivery Note', 'Purchase Invoice', 'Purchase Receipt') \ if self.doctype in ('Sales Invoice', 'Delivery Note', 'Purchase Invoice', 'Purchase Receipt') \
and self.is_internal_transfer(): and self.is_internal_transfer():

View File

@ -191,7 +191,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
item.rejected_qty = flt(item.received_qty - item.qty, precision("rejected_qty", item)); item.rejected_qty = flt(item.received_qty - item.qty, precision("rejected_qty", item));
item.received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(item.received_qty); item.received_stock_qty = flt(item.conversion_factor, precision("conversion_factor", item)) * flt(item.received_qty);
} }
this._super(doc, cdt, cdn); this._super(doc, cdt, cdn);
}, },

View File

@ -40,7 +40,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
cur_frm.cscript.set_gross_profit(item); cur_frm.cscript.set_gross_profit(item);
cur_frm.cscript.calculate_taxes_and_totals(); cur_frm.cscript.calculate_taxes_and_totals();
cur_frm.cscript.calculate_stock_uom_rate(frm, cdt, cdn);
}); });
@ -1121,6 +1121,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
} }
}); });
} }
me.calculate_stock_uom_rate(doc, cdt, cdn);
}, },
conversion_factor: function(doc, cdt, cdn, dont_fetch_price_list_rate) { conversion_factor: function(doc, cdt, cdn, dont_fetch_price_list_rate) {
@ -1141,6 +1142,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
frappe.meta.has_field(doc.doctype, "price_list_currency")) { frappe.meta.has_field(doc.doctype, "price_list_currency")) {
this.apply_price_list(item, true); this.apply_price_list(item, true);
} }
this.calculate_stock_uom_rate(doc, cdt, cdn);
} }
}, },
@ -1161,9 +1163,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
qty: function(doc, cdt, cdn) { qty: function(doc, cdt, cdn) {
let item = frappe.get_doc(cdt, cdn); let item = frappe.get_doc(cdt, cdn);
this.conversion_factor(doc, cdt, cdn, true); this.conversion_factor(doc, cdt, cdn, true);
this.calculate_stock_uom_rate(doc, cdt, cdn);
this.apply_pricing_rule(item, true); this.apply_pricing_rule(item, true);
}, },
calculate_stock_uom_rate: function(doc, cdt, cdn) {
let item = frappe.get_doc(cdt, cdn);
item.stock_uom_rate = flt(item.rate)/flt(item.conversion_factor);
refresh_field("stock_uom_rate", item.name, item.parentfield);
},
service_stop_date: function(frm, cdt, cdn) { service_stop_date: function(frm, cdt, cdn) {
var child = locals[cdt][cdn]; var child = locals[cdt][cdn];
@ -1274,7 +1282,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
this.frm.set_currency_labels(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"], this.frm.set_currency_labels(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"],
company_currency, "items"); company_currency, "items");
this.frm.set_currency_labels(["rate", "net_rate", "price_list_rate", "amount", "net_amount"], this.frm.set_currency_labels(["rate", "net_rate", "price_list_rate", "amount", "net_amount", "stock_uom_rate"],
this.frm.doc.currency, "items"); this.frm.doc.currency, "items");
if(this.frm.fields_dict["operations"]) { if(this.frm.fields_dict["operations"]) {

View File

@ -47,6 +47,7 @@
"base_amount", "base_amount",
"base_net_amount", "base_net_amount",
"pricing_rules", "pricing_rules",
"stock_uom_rate",
"is_free_item", "is_free_item",
"section_break_43", "section_break_43",
"valuation_rate", "valuation_rate",
@ -634,12 +635,20 @@
"print_hide": 1, "print_hide": 1,
"read_only": 1, "read_only": 1,
"report_hide": 1 "report_hide": 1
},
{
"depends_on": "eval: doc.uom != doc.stock_uom",
"fieldname": "stock_uom_rate",
"fieldtype": "Currency",
"label": "Rate of Stock UOM",
"options": "currency",
"read_only": 1
} }
], ],
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2020-05-19 20:48:43.222229", "modified": "2021-01-30 21:39:40.174551",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Selling", "module": "Selling",
"name": "Quotation Item", "name": "Quotation Item",

View File

@ -46,6 +46,7 @@
"base_rate", "base_rate",
"base_amount", "base_amount",
"pricing_rules", "pricing_rules",
"stock_uom_rate",
"is_free_item", "is_free_item",
"section_break_24", "section_break_24",
"net_rate", "net_rate",
@ -214,7 +215,6 @@
"fieldtype": "Link", "fieldtype": "Link",
"label": "UOM", "label": "UOM",
"options": "UOM", "options": "UOM",
"print_hide": 0,
"reqd": 1 "reqd": 1
}, },
{ {
@ -780,12 +780,20 @@
"fieldname": "manufacturing_section_section", "fieldname": "manufacturing_section_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Manufacturing Section" "label": "Manufacturing Section"
},
{
"depends_on": "eval: doc.uom != doc.stock_uom",
"fieldname": "stock_uom_rate",
"fieldtype": "Currency",
"label": "Rate of Stock UOM",
"options": "currency",
"read_only": 1
} }
], ],
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2020-012-07 20:54:32.309460", "modified": "2021-01-30 21:35:07.617320",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Selling", "module": "Selling",
"name": "Sales Order Item", "name": "Sales Order Item",

View File

@ -47,6 +47,7 @@
"base_rate", "base_rate",
"base_amount", "base_amount",
"pricing_rules", "pricing_rules",
"stock_uom_rate",
"is_free_item", "is_free_item",
"section_break_25", "section_break_25",
"net_rate", "net_rate",
@ -743,13 +744,21 @@
"no_copy": 1, "no_copy": 1,
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1
},
{
"depends_on": "eval: doc.uom != doc.stock_uom",
"fieldname": "stock_uom_rate",
"fieldtype": "Currency",
"label": "Rate of Stock UOM",
"options": "currency",
"read_only": 1
} }
], ],
"idx": 1, "idx": 1,
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2020-12-26 17:31:27.029803", "modified": "2021-01-30 21:42:03.767968",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Delivery Note Item", "name": "Delivery Note Item",

View File

@ -48,6 +48,7 @@
"base_rate", "base_rate",
"base_amount", "base_amount",
"pricing_rules", "pricing_rules",
"stock_uom_rate",
"is_free_item", "is_free_item",
"section_break_29", "section_break_29",
"net_rate", "net_rate",
@ -874,6 +875,14 @@
"label": "Received Qty in Stock UOM", "label": "Received Qty in Stock UOM",
"print_hide": 1 "print_hide": 1
}, },
{
"depends_on": "eval: doc.uom != doc.stock_uom",
"fieldname": "stock_uom_rate",
"fieldtype": "Currency",
"label": "Rate of Stock UOM",
"options": "currency",
"read_only": 1
},
{ {
"fieldname": "delivery_note_item", "fieldname": "delivery_note_item",
"fieldtype": "Data", "fieldtype": "Data",
@ -886,7 +895,7 @@
"idx": 1, "idx": 1,
"istable": 1, "istable": 1,
"links": [], "links": [],
"modified": "2020-12-26 16:50:56.479347", "modified": "2021-01-30 21:44:06.918515",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Purchase Receipt Item", "name": "Purchase Receipt Item",