fix: Rate for items with no batch

This commit is contained in:
Deepesh Garg 2020-12-09 12:40:09 +05:30
parent 91e1136d2c
commit bc0a2859e4
5 changed files with 102 additions and 32 deletions

View File

@ -194,6 +194,10 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
this._super(doc, cdt, cdn); this._super(doc, cdt, cdn);
}, },
batch_no: function(doc, cdt, cdn) {
this._super(doc, cdt, cdn);
},
received_qty: function(doc, cdt, cdn) { received_qty: function(doc, cdt, cdn) {
this.calculate_accepted_qty(doc, cdt, cdn) this.calculate_accepted_qty(doc, cdt, cdn)
}, },

View File

@ -1105,7 +1105,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
batch_no: function(doc, cdt, cdn) { batch_no: function(doc, cdt, cdn) {
let item = frappe.get_doc(cdt, cdn); let item = frappe.get_doc(cdt, cdn);
this.apply_pricing_rule(item, true); this.apply_price_list(item, true);
}, },
toggle_conversion_factor: function(item) { toggle_conversion_factor: function(item) {
@ -1412,6 +1412,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
"pricing_rules": d.pricing_rules, "pricing_rules": d.pricing_rules,
"warehouse": d.warehouse, "warehouse": d.warehouse,
"serial_no": d.serial_no, "serial_no": d.serial_no,
"batch_no": d.batch_no,
"price_list_rate": d.price_list_rate, "price_list_rate": d.price_list_rate,
"conversion_factor": d.conversion_factor || 1.0 "conversion_factor": d.conversion_factor || 1.0
}); });

View File

@ -399,6 +399,10 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
} }
}, },
batch_no: function(doc, cdt, cdn) {
this._super(doc, cdt, cdn);
},
qty: function(doc, cdt, cdn) { qty: function(doc, cdt, cdn) {
this._super(doc, cdt, cdn); this._super(doc, cdt, cdn);

View File

@ -18,6 +18,7 @@
"price_list", "price_list",
"customer", "customer",
"supplier", "supplier",
"batch_no",
"column_break_3", "column_break_3",
"buying", "buying",
"selling", "selling",
@ -47,31 +48,41 @@
"oldfieldtype": "Select", "oldfieldtype": "Select",
"options": "Item", "options": "Item",
"reqd": 1, "reqd": 1,
"search_index": 1 "search_index": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "uom", "fieldname": "uom",
"fieldtype": "Link", "fieldtype": "Link",
"label": "UOM", "label": "UOM",
"options": "UOM" "options": "UOM",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"default": "0", "default": "0",
"description": "Quantity that must be bought or sold per UOM", "description": "Quantity that must be bought or sold per UOM",
"fieldname": "packing_unit", "fieldname": "packing_unit",
"fieldtype": "Int", "fieldtype": "Int",
"label": "Packing Unit" "label": "Packing Unit",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "column_break_17", "fieldname": "column_break_17",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "item_name", "fieldname": "item_name",
"fieldtype": "Data", "fieldtype": "Data",
"in_list_view": 1, "in_list_view": 1,
"label": "Item Name", "label": "Item Name",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fetch_from": "item_code.brand", "fetch_from": "item_code.brand",
@ -79,19 +90,25 @@
"fieldtype": "Read Only", "fieldtype": "Read Only",
"in_list_view": 1, "in_list_view": 1,
"label": "Brand", "label": "Brand",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "item_description", "fieldname": "item_description",
"fieldtype": "Text", "fieldtype": "Text",
"label": "Item Description", "label": "Item Description",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "price_list_details", "fieldname": "price_list_details",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Price List", "label": "Price List",
"options": "fa fa-tags" "options": "fa fa-tags",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "price_list", "fieldname": "price_list",
@ -100,7 +117,9 @@
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Price List", "label": "Price List",
"options": "Price List", "options": "Price List",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"bold": 1, "bold": 1,
@ -108,37 +127,49 @@
"fieldname": "customer", "fieldname": "customer",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Customer", "label": "Customer",
"options": "Customer" "options": "Customer",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"depends_on": "eval:doc.buying == 1", "depends_on": "eval:doc.buying == 1",
"fieldname": "supplier", "fieldname": "supplier",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Supplier", "label": "Supplier",
"options": "Supplier" "options": "Supplier",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "column_break_3", "fieldname": "column_break_3",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"default": "0", "default": "0",
"fieldname": "buying", "fieldname": "buying",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Buying", "label": "Buying",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"default": "0", "default": "0",
"fieldname": "selling", "fieldname": "selling",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Selling", "label": "Selling",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "item_details", "fieldname": "item_details",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"options": "fa fa-tag" "options": "fa fa-tag",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"bold": 1, "bold": 1,
@ -146,11 +177,15 @@
"fieldtype": "Link", "fieldtype": "Link",
"label": "Currency", "label": "Currency",
"options": "Currency", "options": "Currency",
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "col_br_1", "fieldname": "col_br_1",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "price_list_rate", "fieldname": "price_list_rate",
@ -162,53 +197,80 @@
"oldfieldname": "ref_rate", "oldfieldname": "ref_rate",
"oldfieldtype": "Currency", "oldfieldtype": "Currency",
"options": "currency", "options": "currency",
"reqd": 1 "reqd": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "section_break_15", "fieldname": "section_break_15",
"fieldtype": "Section Break" "fieldtype": "Section Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"default": "Today", "default": "Today",
"fieldname": "valid_from", "fieldname": "valid_from",
"fieldtype": "Date", "fieldtype": "Date",
"label": "Valid From" "label": "Valid From",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"default": "0", "default": "0",
"fieldname": "lead_time_days", "fieldname": "lead_time_days",
"fieldtype": "Int", "fieldtype": "Int",
"label": "Lead Time in days" "label": "Lead Time in days",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "column_break_18", "fieldname": "column_break_18",
"fieldtype": "Column Break" "fieldtype": "Column Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "valid_upto", "fieldname": "valid_upto",
"fieldtype": "Date", "fieldtype": "Date",
"label": "Valid Upto" "label": "Valid Upto",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "section_break_24", "fieldname": "section_break_24",
"fieldtype": "Section Break" "fieldtype": "Section Break",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "note", "fieldname": "note",
"fieldtype": "Text", "fieldtype": "Text",
"label": "Note" "label": "Note",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "reference", "fieldname": "reference",
"fieldtype": "Data", "fieldtype": "Data",
"in_list_view": 1, "in_list_view": 1,
"label": "Reference" "label": "Reference",
"show_days": 1,
"show_seconds": 1
},
{
"fieldname": "batch_no",
"fieldtype": "Link",
"label": "Batch No",
"options": "Batch",
"show_days": 1,
"show_seconds": 1
} }
], ],
"icon": "fa fa-flag", "icon": "fa fa-flag",
"idx": 1, "idx": 1,
"index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2020-07-06 22:31:32.943475", "modified": "2020-12-08 18:12:15.395772",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Stock", "module": "Stock",
"name": "Item Price", "name": "Item Price",

View File

@ -672,6 +672,8 @@ def get_item_price(args, item_code, ignore_party=False):
and price_list=%(price_list)s and price_list=%(price_list)s
and ifnull(uom, '') in ('', %(uom)s)""" and ifnull(uom, '') in ('', %(uom)s)"""
conditions += "and ifnull(batch_no, '') in ('', %(batch_no)s)"
if not ignore_party: if not ignore_party:
if args.get("customer"): if args.get("customer"):
conditions += " and customer=%(customer)s" conditions += " and customer=%(customer)s"
@ -680,9 +682,6 @@ def get_item_price(args, item_code, ignore_party=False):
else: else:
conditions += "and (customer is null or customer = '') and (supplier is null or supplier = '')" conditions += "and (customer is null or customer = '') and (supplier is null or supplier = '')"
if args.get('batch_no'):
conditions += "and batch_no = %(batch_no)s"
if args.get('transaction_date'): if args.get('transaction_date'):
conditions += """ and %(transaction_date)s between conditions += """ and %(transaction_date)s between
ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31')""" ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31')"""
@ -693,7 +692,7 @@ def get_item_price(args, item_code, ignore_party=False):
return frappe.db.sql(""" select name, price_list_rate, uom return frappe.db.sql(""" select name, price_list_rate, uom
from `tabItem Price` {conditions} from `tabItem Price` {conditions}
order by valid_from desc, uom desc """.format(conditions=conditions), args) order by valid_from desc, batch_no desc, uom desc """.format(conditions=conditions), args)
def get_price_list_rate_for(args, item_code): def get_price_list_rate_for(args, item_code):
""" """