mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 12:49:10 +00:00
[minor] calculate price list rate based on items uom
This commit is contained in:
@@ -143,7 +143,7 @@ def get_pricing_rule_for_item(args):
|
|||||||
})
|
})
|
||||||
|
|
||||||
if args.ignore_pricing_rule or not args.item_code:
|
if args.ignore_pricing_rule or not args.item_code:
|
||||||
if frappe.db.exists(args.doctype, args.name) and args.get("pricing_rule"):
|
if frappe.db.exists(args.doctype, args.name) or args.get("pricing_rule"):
|
||||||
item_details = remove_pricing_rule(args, item_details)
|
item_details = remove_pricing_rule(args, item_details)
|
||||||
return item_details
|
return item_details
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ def get_pricing_rule_for_item(args):
|
|||||||
item_details.margin_rate_or_amount = pricing_rule.margin_rate_or_amount
|
item_details.margin_rate_or_amount = pricing_rule.margin_rate_or_amount
|
||||||
if pricing_rule.price_or_discount == "Price":
|
if pricing_rule.price_or_discount == "Price":
|
||||||
item_details.update({
|
item_details.update({
|
||||||
"price_list_rate": pricing_rule.price/flt(args.conversion_rate) \
|
"price_list_rate": (pricing_rule.price/flt(args.conversion_rate)) * args.conversion_factor or 1.0 \
|
||||||
if args.conversion_rate else 0.0,
|
if args.conversion_rate else 0.0,
|
||||||
"discount_percentage": 0.0
|
"discount_percentage": 0.0
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -186,7 +186,6 @@ class AccountsController(TransactionBase):
|
|||||||
|
|
||||||
ret = get_item_details(args)
|
ret = get_item_details(args)
|
||||||
|
|
||||||
|
|
||||||
for fieldname, value in ret.items():
|
for fieldname, value in ret.items():
|
||||||
if item.meta.get_field(fieldname) and value is not None:
|
if item.meta.get_field(fieldname) and value is not None:
|
||||||
if (item.get(fieldname) is None or fieldname in force_item_fields):
|
if (item.get(fieldname) is None or fieldname in force_item_fields):
|
||||||
@@ -200,6 +199,10 @@ class AccountsController(TransactionBase):
|
|||||||
if stock_qty != len(item.get('serial_no').split('\n')):
|
if stock_qty != len(item.get('serial_no').split('\n')):
|
||||||
item.set(fieldname, value)
|
item.set(fieldname, value)
|
||||||
|
|
||||||
|
elif fieldname in ["conversion_factor", "price_list_rate"]:
|
||||||
|
if for_validate and not item.get(fieldname):
|
||||||
|
item.set(fieldname, value)
|
||||||
|
|
||||||
if ret.get("pricing_rule"):
|
if ret.get("pricing_rule"):
|
||||||
# if user changed the discount percentage then set user's discount percentage ?
|
# if user changed the discount percentage then set user's discount percentage ?
|
||||||
item.set("discount_percentage", ret.get("discount_percentage"))
|
item.set("discount_percentage", ret.get("discount_percentage"))
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class SellingController(StockController):
|
|||||||
|
|
||||||
# set contact and address details for customer, if they are not mentioned
|
# set contact and address details for customer, if they are not mentioned
|
||||||
self.set_missing_lead_customer_details()
|
self.set_missing_lead_customer_details()
|
||||||
self.set_price_list_and_item_details()
|
self.set_price_list_and_item_details(for_validate)
|
||||||
|
|
||||||
def set_missing_lead_customer_details(self):
|
def set_missing_lead_customer_details(self):
|
||||||
if getattr(self, "customer", None):
|
if getattr(self, "customer", None):
|
||||||
@@ -60,9 +60,9 @@ class SellingController(StockController):
|
|||||||
posting_date=self.get('transaction_date') or self.get('posting_date'),
|
posting_date=self.get('transaction_date') or self.get('posting_date'),
|
||||||
company=self.company))
|
company=self.company))
|
||||||
|
|
||||||
def set_price_list_and_item_details(self):
|
def set_price_list_and_item_details(self, for_validate):
|
||||||
self.set_price_list_currency("Selling")
|
self.set_price_list_currency("Selling")
|
||||||
self.set_missing_item_details()
|
self.set_missing_item_details(for_validate=for_validate)
|
||||||
|
|
||||||
def apply_shipping_rule(self):
|
def apply_shipping_rule(self):
|
||||||
if self.shipping_rule:
|
if self.shipping_rule:
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class calculate_taxes_and_totals(object):
|
|||||||
|
|
||||||
if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item']:
|
if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item']:
|
||||||
item.total_margin = self.calculate_margin(item)
|
item.total_margin = self.calculate_margin(item)
|
||||||
|
|
||||||
item.rate = flt(item.total_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate"))\
|
item.rate = flt(item.total_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate"))\
|
||||||
if item.total_margin > 0 else item.rate
|
if item.total_margin > 0 else item.rate
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
|||||||
if(item.margin_type == "Percentage"){
|
if(item.margin_type == "Percentage"){
|
||||||
item.total_margin = flt(item.price_list_rate)
|
item.total_margin = flt(item.price_list_rate)
|
||||||
+ flt(item.price_list_rate) * ( flt(item.margin_rate_or_amount) / 100);
|
+ flt(item.price_list_rate) * ( flt(item.margin_rate_or_amount) / 100);
|
||||||
}else{
|
} else {
|
||||||
item.total_margin = flt(item.price_list_rate) + flt(item.margin_rate_or_amount);
|
item.total_margin = flt(item.price_list_rate) + flt(item.margin_rate_or_amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -284,6 +284,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if(!r.exc) {
|
if(!r.exc) {
|
||||||
me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
|
me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
|
||||||
|
me.toggle_conversion_factor(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -568,9 +569,17 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
frappe.model.round_floats_in(item, ["qty", "conversion_factor"]);
|
frappe.model.round_floats_in(item, ["qty", "conversion_factor"]);
|
||||||
item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item));
|
item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item));
|
||||||
refresh_field("stock_qty", item.name, item.parentfield);
|
refresh_field("stock_qty", item.name, item.parentfield);
|
||||||
|
this.toggle_conversion_factor(item);
|
||||||
|
this.apply_price_list();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
toggle_conversion_factor: function(item) {
|
||||||
|
// toggle read only property for conversion factor field if the uom and stock uom are same
|
||||||
|
this.frm.fields_dict.items.grid.toggle_enable("conversion_factor",
|
||||||
|
(item.uom != item.stock_uom)? true: false)
|
||||||
|
},
|
||||||
|
|
||||||
qty: function(doc, cdt, cdn) {
|
qty: function(doc, cdt, cdn) {
|
||||||
this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true);
|
this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true);
|
||||||
this.conversion_factor(doc, cdt, cdn);
|
this.conversion_factor(doc, cdt, cdn);
|
||||||
@@ -766,6 +775,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
"name": me.frm.doc.name,
|
"name": me.frm.doc.name,
|
||||||
"is_return": cint(me.frm.doc.is_return),
|
"is_return": cint(me.frm.doc.is_return),
|
||||||
"update_stock": in_list(['Sales Invoice', 'Purchase Invoice'], me.frm.doc.doctype) ? cint(me.frm.doc.update_stock) : 0,
|
"update_stock": in_list(['Sales Invoice', 'Purchase Invoice'], me.frm.doc.doctype) ? cint(me.frm.doc.update_stock) : 0,
|
||||||
|
"conversion_factor": me.frm.doc.conversion_factor
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -785,7 +795,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
"pricing_rule": d.pricing_rule,
|
"pricing_rule": d.pricing_rule,
|
||||||
"warehouse": d.warehouse,
|
"warehouse": d.warehouse,
|
||||||
"serial_no": d.serial_no,
|
"serial_no": d.serial_no,
|
||||||
"conversion_factor": d.conversion_factor
|
"conversion_factor": d.conversion_factor || 1.0
|
||||||
});
|
});
|
||||||
|
|
||||||
// if doctype is Quotation Item / Sales Order Iten then add Margin Type and rate in item_list
|
// if doctype is Quotation Item / Sales Order Iten then add Margin Type and rate in item_list
|
||||||
@@ -812,16 +822,13 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
for(var i=0, l=children.length; i<l; i++) {
|
for(var i=0, l=children.length; i<l; i++) {
|
||||||
var d = children[i];
|
var d = children[i];
|
||||||
var existing_pricing_rule = frappe.model.get_value(d.doctype, d.name, "pricing_rule");
|
var existing_pricing_rule = frappe.model.get_value(d.doctype, d.name, "pricing_rule");
|
||||||
|
|
||||||
for(var k in d) {
|
for(var k in d) {
|
||||||
var v = d[k];
|
var v = d[k];
|
||||||
if (["doctype", "name"].indexOf(k)===-1) {
|
if (["doctype", "name"].indexOf(k)===-1) {
|
||||||
if(k=="price_list_rate") {
|
if(k=="price_list_rate") {
|
||||||
if(flt(v) != flt(d.price_list_rate)) price_list_rate_changed = true;
|
if(flt(v) != flt(d.price_list_rate)) price_list_rate_changed = true;
|
||||||
}
|
}
|
||||||
if(v) {
|
frappe.model.set_value(d.doctype, d.name, k, v);
|
||||||
frappe.model.set_value(d.doctype, d.name, k, v);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -159,7 +159,6 @@ def get_basic_details(args, item):
|
|||||||
item.get("taxes")))),
|
item.get("taxes")))),
|
||||||
"uom": item.stock_uom,
|
"uom": item.stock_uom,
|
||||||
"min_order_qty": flt(item.min_order_qty) if args.doctype == "Material Request" else "",
|
"min_order_qty": flt(item.min_order_qty) if args.doctype == "Material Request" else "",
|
||||||
"conversion_factor": 1.0,
|
|
||||||
"qty": args.qty or 1.0,
|
"qty": args.qty or 1.0,
|
||||||
"stock_qty": args.qty or 1.0,
|
"stock_qty": args.qty or 1.0,
|
||||||
"price_list_rate": 0.0,
|
"price_list_rate": 0.0,
|
||||||
@@ -178,11 +177,14 @@ def get_basic_details(args, item):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# calculate conversion factor
|
# calculate conversion factor
|
||||||
conversion_factor = args.get("conversion_factor") or get_conversion_factor(item.item_code, args.uom).get("conversion_factor") or 1.0
|
if item.stock_uom == args.uom:
|
||||||
out.update({
|
out.conversion_factor = 1.0
|
||||||
"conversion_factor": conversion_factor,
|
else:
|
||||||
"stock_qty": out.qty * conversion_factor
|
out.conversion_factor = args.conversion_factor or \
|
||||||
})
|
get_conversion_factor(item.item_code, args.uom).get("conversion_factor") or 1.0
|
||||||
|
|
||||||
|
args.conversion_factor = out.conversion_factor
|
||||||
|
out.stock_qty = out.qty * out.conversion_factor
|
||||||
|
|
||||||
# if default specified in item is for another company, fetch from company
|
# if default specified in item is for another company, fetch from company
|
||||||
for d in [["Account", "income_account", "default_income_account"],
|
for d in [["Account", "income_account", "default_income_account"],
|
||||||
@@ -235,6 +237,8 @@ def get_price_list_rate(args, item_doc, out):
|
|||||||
out.price_list_rate = flt(price_list_rate) * flt(args.plc_conversion_rate) \
|
out.price_list_rate = flt(price_list_rate) * flt(args.plc_conversion_rate) \
|
||||||
/ flt(args.conversion_rate)
|
/ flt(args.conversion_rate)
|
||||||
|
|
||||||
|
out.price_list_rate = flt(out.price_list_rate * (args.conversion_factor or 1.0))
|
||||||
|
|
||||||
if not out.price_list_rate and args.transaction_type=="buying":
|
if not out.price_list_rate and args.transaction_type=="buying":
|
||||||
from erpnext.stock.doctype.item.item import get_last_purchase_details
|
from erpnext.stock.doctype.item.item import get_last_purchase_details
|
||||||
out.update(get_last_purchase_details(item_doc.name,
|
out.update(get_last_purchase_details(item_doc.name,
|
||||||
|
|||||||
Reference in New Issue
Block a user