Merge branch 'version-12-hotfix' into mr-se-warehouse-validation-hotfix

This commit is contained in:
Nabin Hait
2021-01-05 09:30:09 +05:30
committed by GitHub
4 changed files with 68 additions and 17 deletions

View File

@@ -153,8 +153,8 @@ def update_multi_mode_option(doc, pos_profile):
def get_mode_of_payment(doc): def get_mode_of_payment(doc):
return frappe.db.sql(""" return frappe.db.sql("""
select mpa.default_account, mpa.parent, mp.type as type select mpa.default_account, mpa.parent, mp.type as type
from `tabMode of Payment Account` mpa,`tabMode of Payment` mp from `tabMode of Payment Account` mpa,`tabMode of Payment` mp
where mpa.parent = mp.name and mpa.company = %(company)s and mp.enabled = 1""", where mpa.parent = mp.name and mpa.company = %(company)s and mp.enabled = 1""",
{'company': doc.company}, as_dict=1) {'company': doc.company}, as_dict=1)
@@ -394,6 +394,14 @@ def get_pricing_rule_data(doc):
between ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31') between ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31')
order by priority desc, name desc""", order by priority desc, name desc""",
{'company': doc.company, 'price_list': doc.selling_price_list, 'date': nowdate()}, as_dict=1) {'company': doc.company, 'price_list': doc.selling_price_list, 'date': nowdate()}, as_dict=1)
for row in pricing_rules:
if row.apply_on:
doctype = "Pricing Rule " + row.apply_on
apply_on = frappe.scrub(row.apply_on)
row[apply_on] = [d.get(apply_on) for d in frappe.get_all(doctype,
filters = {"parent": row.name}, fields = [apply_on])]
return pricing_rules return pricing_rules
@@ -434,10 +442,10 @@ def make_invoice(pos_profile, doc_list={}, email_queue_list={}, customers_list={
name_list.append(name) name_list.append(name)
email_queue = make_email_queue(email_queue_list) email_queue = make_email_queue(email_queue_list)
if isinstance(pos_profile, string_types): if isinstance(pos_profile, string_types):
pos_profile = json.loads(pos_profile) pos_profile = json.loads(pos_profile)
customers = get_customers_list(pos_profile) customers = get_customers_list(pos_profile)
return { return {
'invoice': name_list, 'invoice': name_list,

View File

@@ -2018,34 +2018,57 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
apply_pricing_rule: function () { apply_pricing_rule: function () {
var me = this; var me = this;
var remove_item = false;
$.each(this.frm.doc["items"], function (n, item) { $.each(this.frm.doc["items"], function (n, item) {
var pricing_rule = me.get_pricing_rule(item) var pricing_rule = me.get_pricing_rule(item)
me.validate_pricing_rule(pricing_rule) me.validate_pricing_rule(pricing_rule)
if (pricing_rule.length) { if (pricing_rule.length) {
item.pricing_rule = pricing_rule[0].name; if (pricing_rule[0].price_or_product_discount == "Price") {
item.margin_type = pricing_rule[0].margin_type; item.pricing_rule = pricing_rule[0].name;
item.price_list_rate = pricing_rule[0].price || item.price_list_rate; item.margin_type = pricing_rule[0].margin_type;
item.margin_rate_or_amount = pricing_rule[0].margin_rate_or_amount; item.price_list_rate = pricing_rule[0].price || item.price_list_rate;
item.discount_percentage = pricing_rule[0].discount_percentage || 0.0; item.margin_rate_or_amount = pricing_rule[0].margin_rate_or_amount;
me.apply_pricing_rule_on_item(item) item.discount_percentage = pricing_rule[0].discount_percentage || 0.0;
me.apply_pricing_rule_on_item(item)
} else {
me.child = frappe.model.add_child(me.frm.doc, me.frm.doc.doctype + " Item", "items");
me.child.item_code = pricing_rule[0].same_item ? item.item_code : pricing_rule[0].free_item;
me.child.item_name = pricing_rule[0].same_item ? item.item_name : pricing_rule[0].free_item;
me.child.stock_uom = pricing_rule[0].same_item ? item.stock_uom : pricing_rule[0].free_item_uom;
me.child.uom = pricing_rule[0].same_item ? item.uom : pricing_rule[0].free_item_uom;
me.child.conversion_factor = 1;
me.child.qty = pricing_rule.qty || 1;
me.child.is_free_item = 1;
me.child.brand = pricing_rule[0].same_item ? item.brand : "";
me.child.description = pricing_rule[0].same_item ? item.description : pricing_rule[0].free_item;
}
} else if (item.pricing_rule) { } else if (item.pricing_rule) {
item.price_list_rate = me.price_list_data[item.item_code] item.price_list_rate = me.price_list_data[item.item_code]
item.margin_rate_or_amount = 0.0; item.margin_rate_or_amount = 0.0;
item.discount_percentage = 0.0; item.discount_percentage = 0.0;
item.pricing_rule = null; item.pricing_rule = null;
me.apply_pricing_rule_on_item(item) me.apply_pricing_rule_on_item(item)
} else if (item.is_free_item) {
remove_item = true;
item.qty = 0
} }
if(item.discount_percentage > 0) { if(item.discount_percentage > 0) {
me.apply_pricing_rule_on_item(item) me.apply_pricing_rule_on_item(item)
} }
}) });
if (remove_item) {
this.remove_zero_qty_items_from_cart();
}
}, },
get_pricing_rule: function (item) { get_pricing_rule: function (item) {
var me = this; var me = this;
return $.grep(this.pricing_rules, function (data) { return $.grep(this.pricing_rules, function (data) {
if (item.qty >= data.min_qty && (item.qty <= (data.max_qty ? data.max_qty : item.qty))) { me.get_mixed_min_max_qty_and_amt(data, item);
if (data.mixed_qty >= data.min_qty && (data.mixed_qty <= (data.max_qty ? data.max_qty : data.mixed_qty))) {
if (me.validate_item_condition(data, item)) { if (me.validate_item_condition(data, item)) {
if (in_list(['Customer', 'Customer Group', 'Territory', 'Campaign'], data.applicable_for)) { if (in_list(['Customer', 'Customer Group', 'Territory', 'Campaign'], data.applicable_for)) {
return me.validate_condition(data) return me.validate_condition(data)
@@ -2057,11 +2080,26 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
}) })
}, },
get_mixed_min_max_qty_and_amt: function(data, item) {
var apply_on = frappe.model.scrub(data.apply_on);
data.mixed_qty = 0.0
if (data.mixed_conditions && in_list(data[apply_on], item[apply_on])) {
this.frm.doc.items.forEach(d => {
if (in_list(data[apply_on], d[apply_on])) {
data.mixed_qty += d.qty;
data.mixed_amt += d.amount;
}
});
} else {
data.mixed_qty = item.qty;
data.mixed_amt = item.amount;
}
},
validate_item_condition: function (data, item) { validate_item_condition: function (data, item) {
var apply_on = frappe.model.scrub(data.apply_on); var apply_on = frappe.model.scrub(data.apply_on);
return (data.apply_on == 'Item Group') return in_list(data[apply_on], item[apply_on]);
? this.validate_item_group(data.item_group, item.item_group) : (data[apply_on] == item[apply_on]);
}, },
validate_item_group: function (pr_item_group, cart_item_group) { validate_item_group: function (pr_item_group, cart_item_group) {

View File

@@ -26,7 +26,8 @@ def delete_company_transactions(company_name):
tabDocField where fieldtype='Link' and options='Company'"""): tabDocField where fieldtype='Link' and options='Company'"""):
if doctype not in ("Account", "Cost Center", "Warehouse", "Budget", if doctype not in ("Account", "Cost Center", "Warehouse", "Budget",
"Party Account", "Employee", "Sales Taxes and Charges Template", "Party Account", "Employee", "Sales Taxes and Charges Template",
"Purchase Taxes and Charges Template", "POS Profile", 'BOM'): "Purchase Taxes and Charges Template", "POS Profile", 'BOM',
"Item default", "Customer", "Supplier"):
delete_for_doctype(doctype, company_name) delete_for_doctype(doctype, company_name)
# reset company values # reset company values

View File

@@ -1010,7 +1010,7 @@ class StockEntry(StockController):
wo = frappe.get_doc("Work Order", self.work_order) wo = frappe.get_doc("Work Order", self.work_order)
wo_items = frappe.get_all('Work Order Item', wo_items = frappe.get_all('Work Order Item',
filters={'parent': self.work_order}, filters={'parent': self.work_order},
fields=["item_code", "required_qty", "consumed_qty", "transferred_qty"] fields=["item_code", "required_qty", "consumed_qty", "transferred_qty", "source_warehouse"]
) )
work_order_qty = wo.material_transferred_for_manufacturing or wo.qty work_order_qty = wo.material_transferred_for_manufacturing or wo.qty
@@ -1028,9 +1028,13 @@ class StockEntry(StockController):
qty = req_qty_each * flt(self.fg_completed_qty) qty = req_qty_each * flt(self.fg_completed_qty)
if qty > 0: if qty > 0:
from_warehouse = wo.wip_warehouse
if wo.skip_transfer and not wo.from_wip_warehouse:
from_warehouse = item.source_warehouse
self.add_to_stock_entry_detail({ self.add_to_stock_entry_detail({
item.item_code: { item.item_code: {
"from_warehouse": wo.wip_warehouse, "from_warehouse": from_warehouse,
"to_warehouse": "", "to_warehouse": "",
"qty": qty, "qty": qty,
"item_name": item.item_name, "item_name": item.item_name,