Merge branch 'v12-pre-release' into version-12

This commit is contained in:
Saurabh
2020-08-25 20:01:54 +05:30
5 changed files with 21 additions and 13 deletions

View File

@@ -5,7 +5,7 @@ import frappe
from erpnext.hooks import regional_overrides
from frappe.utils import getdate
__version__ = '12.11.0'
__version__ = '12.11.1'
def get_default_company(user=None):
'''Get default company for user'''

View File

@@ -241,7 +241,7 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa
update_args_for_pricing_rule(args)
pricing_rules = (get_applied_pricing_rules(args)
pricing_rules = (get_applied_pricing_rules(args.get('pricing_rules'))
if for_validate and args.get("pricing_rules") else get_pricing_rules(args, doc))
if pricing_rules:
@@ -369,8 +369,10 @@ def set_discount_amount(rate, item_details):
item_details.rate = rate
def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None):
from erpnext.accounts.doctype.pricing_rule.utils import get_pricing_rule_items
for d in json.loads(pricing_rules):
from erpnext.accounts.doctype.pricing_rule.utils import (get_applied_pricing_rules,
get_pricing_rule_items)
for d in get_applied_pricing_rules(pricing_rules):
if not d or not frappe.db.exists("Pricing Rule", d): continue
pricing_rule = frappe.get_cached_doc('Pricing Rule', d)
@@ -393,7 +395,8 @@ def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None):
items = get_pricing_rule_items(pricing_rule)
item_details.apply_on = (frappe.scrub(pricing_rule.apply_rule_on_other)
if pricing_rule.apply_rule_on_other else frappe.scrub(pricing_rule.get('apply_on')))
item_details.applied_on_items = ','.join(items)
item_details.applied_on_items = json.dumps(items)
item_details.price_or_product_discount = pricing_rule.price_or_product_discount
item_details.pricing_rules = ''

View File

@@ -470,9 +470,14 @@ def apply_pricing_rule_on_transaction(doc):
apply_pricing_rule_for_free_items(doc, item_details.free_item_data)
doc.set_missing_values()
def get_applied_pricing_rules(item_row):
return (json.loads(item_row.get("pricing_rules"))
if item_row.get("pricing_rules") else [])
def get_applied_pricing_rules(pricing_rules):
if pricing_rules:
if pricing_rules.startswith('['):
return json.loads(pricing_rules)
else:
return pricing_rules.split(',')
return []
def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None):
free_item = pricing_rule.free_item

View File

@@ -325,7 +325,7 @@ class AccountsController(TransactionBase):
apply_pricing_rule_for_free_items(self, pricing_rule_args.get('free_item_data'))
elif pricing_rule_args.get("validate_applied_rule"):
for pricing_rule in get_applied_pricing_rules(item):
for pricing_rule in get_applied_pricing_rules(item.get('pricing_rules')):
pricing_rule_doc = frappe.get_cached_doc("Pricing Rule", pricing_rule)
for field in ['discount_percentage', 'discount_amount', 'rate']:
if item.get(field) < pricing_rule_doc.get(field):

View File

@@ -1413,9 +1413,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
if (data && data.apply_rule_on_other_items) {
me.frm.doc.items.forEach(d => {
if (in_list(data.apply_rule_on_other_items, d[data.apply_rule_on])) {
if (in_list(JSON.parse(data.apply_rule_on_other_items), d[data.apply_rule_on])) {
for(var k in data) {
if (in_list(fields, k) && data[k] && (data.price_or_product_discount === 'price' || k === 'pricing_rules')) {
if (in_list(fields, k) && data[k] && (data.price_or_product_discount === 'Price' || k === 'pricing_rules')) {
frappe.model.set_value(d.doctype, d.name, k, data[k]);
}
}
@@ -1499,9 +1499,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
me.frm.doc.items = items;
refresh_field('items');
} else if(item.applied_on_items && item.apply_on) {
const applied_on_items = item.applied_on_items.split(',');
const applied_on_items = JSON.parse(item.applied_on_items);
me.frm.doc.items.forEach(row => {
if(applied_on_items.includes(row[item.apply_on])) {
if(in_list(applied_on_items, row[item.apply_on])) {
fields.forEach(f => {
row[f] = 0;
});