Merge pull request #32634 from frappe/version-13-hotfix

chore: release v13
This commit is contained in:
Deepesh Garg
2022-10-19 09:24:40 +05:30
committed by GitHub
13 changed files with 221 additions and 341 deletions

View File

@@ -269,6 +269,18 @@ def get_serial_no_for_item(args):
return item_details
def update_pricing_rule_uom(pricing_rule, args):
child_doc = {"Item Code": "items", "Item Group": "item_groups", "Brand": "brands"}.get(
pricing_rule.apply_on
)
apply_on_field = frappe.scrub(pricing_rule.apply_on)
for row in pricing_rule.get(child_doc):
if row.get(apply_on_field) == args.get(apply_on_field):
pricing_rule.uom = row.uom
def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=False):
from erpnext.accounts.doctype.pricing_rule.utils import (
get_applied_pricing_rules,
@@ -325,7 +337,8 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa
if isinstance(pricing_rule, string_types):
pricing_rule = frappe.get_cached_doc("Pricing Rule", pricing_rule)
pricing_rule.apply_rule_on_other_items = get_pricing_rule_items(pricing_rule)
update_pricing_rule_uom(pricing_rule, args)
pricing_rule.apply_rule_on_other_items = get_pricing_rule_items(pricing_rule) or []
if pricing_rule.get("suggestion"):
continue
@@ -439,12 +452,15 @@ def apply_price_discount_rule(pricing_rule, item_details, args):
if pricing_rule.currency == args.currency:
pricing_rule_rate = pricing_rule.rate
# TODO https://github.com/frappe/erpnext/pull/23636 solve this in some other way.
if pricing_rule_rate:
is_blank_uom = pricing_rule.get("uom") != args.get("uom")
# Override already set price list rate (from item price)
# if pricing_rule_rate > 0
item_details.update(
{
"price_list_rate": pricing_rule_rate * args.get("conversion_factor", 1),
"price_list_rate": pricing_rule_rate
* (args.get("conversion_factor", 1) if is_blank_uom else 1),
}
)
item_details.update({"discount_percentage": 0.0})

View File

@@ -597,6 +597,121 @@ class TestPricingRule(unittest.TestCase):
frappe.get_doc("Item Price", {"item_code": "Water Flask"}).delete()
item.delete()
def test_item_price_with_blank_uom_pricing_rule(self):
properties = {
"item_code": "Item Blank UOM",
"stock_uom": "Nos",
"sales_uom": "Box",
"uoms": [dict(uom="Box", conversion_factor=10)],
}
item = make_item(properties=properties)
make_item_price("Item Blank UOM", "_Test Price List", 100)
pricing_rule_record = {
"doctype": "Pricing Rule",
"title": "_Test Item Blank UOM Rule",
"apply_on": "Item Code",
"items": [
{
"item_code": "Item Blank UOM",
}
],
"selling": 1,
"currency": "INR",
"rate_or_discount": "Rate",
"rate": 101,
"company": "_Test Company",
}
rule = frappe.get_doc(pricing_rule_record)
rule.insert()
si = create_sales_invoice(
do_not_save=True, item_code="Item Blank UOM", uom="Box", conversion_factor=10
)
si.selling_price_list = "_Test Price List"
si.save()
# If UOM is blank consider it as stock UOM and apply pricing_rule on all UOM.
# rate is 101, Selling UOM is Box that have conversion_factor of 10 so 101 * 10 = 1010
self.assertEqual(si.items[0].price_list_rate, 1010)
self.assertEqual(si.items[0].rate, 1010)
si.delete()
si = create_sales_invoice(do_not_save=True, item_code="Item Blank UOM", uom="Nos")
si.selling_price_list = "_Test Price List"
si.save()
# UOM is blank so consider it as stock UOM and apply pricing_rule on all UOM.
# rate is 101, Selling UOM is Nos that have conversion_factor of 1 so 101 * 1 = 101
self.assertEqual(si.items[0].price_list_rate, 101)
self.assertEqual(si.items[0].rate, 101)
si.delete()
rule.delete()
frappe.get_doc("Item Price", {"item_code": "Item Blank UOM"}).delete()
item.delete()
def test_item_price_with_selling_uom_pricing_rule(self):
properties = {
"item_code": "Item UOM other than Stock",
"stock_uom": "Nos",
"sales_uom": "Box",
"uoms": [dict(uom="Box", conversion_factor=10)],
}
item = make_item(properties=properties)
make_item_price("Item UOM other than Stock", "_Test Price List", 100)
pricing_rule_record = {
"doctype": "Pricing Rule",
"title": "_Test Item UOM other than Stock Rule",
"apply_on": "Item Code",
"items": [
{
"item_code": "Item UOM other than Stock",
"uom": "Box",
}
],
"selling": 1,
"currency": "INR",
"rate_or_discount": "Rate",
"rate": 101,
"company": "_Test Company",
}
rule = frappe.get_doc(pricing_rule_record)
rule.insert()
si = create_sales_invoice(
do_not_save=True, item_code="Item UOM other than Stock", uom="Box", conversion_factor=10
)
si.selling_price_list = "_Test Price List"
si.save()
# UOM is Box so apply pricing_rule only on Box UOM.
# Selling UOM is Box and as both UOM are same no need to multiply by conversion_factor.
self.assertEqual(si.items[0].price_list_rate, 101)
self.assertEqual(si.items[0].rate, 101)
si.delete()
si = create_sales_invoice(do_not_save=True, item_code="Item UOM other than Stock", uom="Nos")
si.selling_price_list = "_Test Price List"
si.save()
# UOM is Box so pricing_rule won't apply as selling_uom is Nos.
# As Pricing Rule is not applied price of 100 will be fetched from Item Price List.
self.assertEqual(si.items[0].price_list_rate, 100)
self.assertEqual(si.items[0].rate, 100)
si.delete()
rule.delete()
frappe.get_doc("Item Price", {"item_code": "Item UOM other than Stock"}).delete()
item.delete()
def test_pricing_rule_for_different_currency(self):
make_item("Test Sanitizer Item")

View File

@@ -111,6 +111,12 @@ def _get_pricing_rules(apply_on, args, values):
)
if apply_on_field == "item_code":
if args.get("uom", None):
item_conditions += (
" and ({child_doc}.uom='{item_uom}' or IFNULL({child_doc}.uom, '')='')".format(
child_doc=child_doc, item_uom=args.get("uom")
)
)
if "variant_of" not in args:
args.variant_of = frappe.get_cached_value("Item", args.item_code, "variant_of")

View File

@@ -31,7 +31,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
this._super();
// Ignore linked advances
this.frm.ignore_doctypes_on_cancel_all = ['Journal Entry', 'Payment Entry'];
this.frm.ignore_doctypes_on_cancel_all = ['Journal Entry', 'Payment Entry', 'Purchase Invoice'];
if(!this.frm.doc.__islocal) {
// show credit_to in print format

View File

@@ -1368,7 +1368,14 @@ class PurchaseInvoice(BuyingController):
frappe.db.set(self, "status", "Cancelled")
unlink_inter_company_doc(self.doctype, self.name, self.inter_company_invoice_reference)
self.ignore_linked_doctypes = ("GL Entry", "Stock Ledger Entry", "Repost Item Valuation")
self.ignore_linked_doctypes = (
"GL Entry",
"Stock Ledger Entry",
"Repost Item Valuation",
"Purchase Invoice",
)
self.update_advance_tax_references(cancel=1)
def update_project(self):

View File

@@ -3729,7 +3729,7 @@ def create_sales_invoice(**args):
"discount_amount": args.discount_amount or 0,
"cost_center": args.cost_center or "_Test Cost Center - _TC",
"serial_no": args.serial_no,
"conversion_factor": 1,
"conversion_factor": args.get("conversion_factor", 1),
"incoming_rate": args.incoming_rate or 0,
"batch_no": args.batch_no or None,
},

View File

@@ -18,7 +18,7 @@ from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import (
get_party_tax_withholding_details,
)
from erpnext.accounts.party import get_party_account_currency
from erpnext.accounts.party import get_party_account, get_party_account_currency
from erpnext.buying.utils import check_on_hold_or_closed_status, validate_for_items
from erpnext.controllers.buying_controller import BuyingController
from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
@@ -533,6 +533,7 @@ def get_mapped_purchase_invoice(source_name, target_doc=None, ignore_permissions
target.set_advances()
target.set_payment_schedule()
target.credit_to = get_party_account("Supplier", source.supplier, source.company)
def update_item(obj, target, source_parent):
target.amount = flt(obj.amount) - flt(obj.billed_amt)

View File

@@ -334,8 +334,6 @@ has_website_permission = {
"Patient": "erpnext.healthcare.web_form.personal_details.personal_details.has_website_permission",
}
dump_report_map = "erpnext.startup.report_data_map.data_map"
before_tests = "erpnext.setup.utils.before_tests"
standard_queries = {

View File

@@ -545,6 +545,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
if(!this.validate_company_and_party()) {
this.frm.fields_dict["items"].grid.grid_rows[item.idx - 1].remove();
} else {
item.pricing_rules = ''
return this.frm.call({
method: "erpnext.stock.get_item_details.get_item_details",
child: item,
@@ -1160,6 +1161,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
uom: function(doc, cdt, cdn) {
var me = this;
var item = frappe.get_doc(cdt, cdn);
item.pricing_rules = ''
if(item.item_code && item.uom) {
return this.frm.call({
method: "erpnext.stock.get_item_details.get_conversion_factor",
@@ -1236,6 +1238,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
qty: function(doc, cdt, cdn) {
let item = frappe.get_doc(cdt, cdn);
item.pricing_rules = ''
this.conversion_factor(doc, cdt, cdn, true);
this.calculate_stock_uom_rate(doc, cdt, cdn);
this.apply_pricing_rule(item, true);

View File

@@ -19,6 +19,7 @@ from erpnext.accounts.doctype.sales_invoice.sales_invoice import (
update_linked_doc,
validate_inter_company_party,
)
from erpnext.accounts.party import get_party_account
from erpnext.controllers.selling_controller import SellingController
from erpnext.manufacturing.doctype.production_plan.production_plan import (
get_items_for_material_requests,
@@ -797,6 +798,8 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
if source.loyalty_points and source.order_type == "Shopping Cart":
target.redeem_loyalty_points = 1
target.debit_to = get_party_account("Customer", source.customer, source.company)
def update_item(source, target, source_parent):
target.amount = flt(source.amount) - flt(source.billed_amt)
target.base_amount = target.amount * flt(source_parent.conversion_rate)

View File

@@ -1,13 +1,71 @@
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
frappe.ui.form.on('Brand', {
setup: (frm) => {
frm.fields_dict["brand_defaults"].grid.get_field("default_warehouse").get_query = function(doc, cdt, cdn) {
const row = locals[cdt][cdn];
return {
filters: { company: row.company }
}
}
frm.fields_dict["brand_defaults"].grid.get_field("default_discount_account").get_query = function(doc, cdt, cdn) {
const row = locals[cdt][cdn];
return {
filters: {
'report_type': 'Profit and Loss',
'company': row.company,
"is_group": 0
}
};
}
//--------- ONLOAD -------------
cur_frm.cscript.onload = function(doc, cdt, cdn) {
frm.fields_dict["brand_defaults"].grid.get_field("buying_cost_center").get_query = function(doc, cdt, cdn) {
const row = locals[cdt][cdn];
return {
filters: {
"is_group": 0,
"company": row.company
}
}
}
}
frm.fields_dict["brand_defaults"].grid.get_field("expense_account").get_query = function(doc, cdt, cdn) {
const row = locals[cdt][cdn];
return {
query: "erpnext.controllers.queries.get_expense_account",
filters: { company: row.company }
}
}
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
frm.fields_dict["brand_defaults"].grid.get_field("default_provisional_account").get_query = function(doc, cdt, cdn) {
const row = locals[cdt][cdn];
return {
filters: {
"company": row.company,
"root_type": ["in", ["Liability", "Asset"]],
"is_group": 0
}
};
}
}
frm.fields_dict["brand_defaults"].grid.get_field("selling_cost_center").get_query = function(doc, cdt, cdn) {
const row = locals[cdt][cdn];
return {
filters: {
"is_group": 0,
"company": row.company
}
}
}
frm.fields_dict["brand_defaults"].grid.get_field("income_account").get_query = function(doc, cdt, cdn) {
const row = locals[cdt][cdn];
return {
query: "erpnext.controllers.queries.get_income_account",
filters: { company: row.company }
}
}
}
});

View File

@@ -1,327 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
# mappings for table dumps
# "remember to add indexes!"
data_map = {
"Company": {"columns": ["name"], "conditions": ["docstatus < 2"]},
"Fiscal Year": {
"columns": ["name", "year_start_date", "year_end_date"],
"conditions": ["docstatus < 2"],
},
# Accounts
"Account": {
"columns": ["name", "parent_account", "lft", "rgt", "report_type", "company", "is_group"],
"conditions": ["docstatus < 2"],
"order_by": "lft",
"links": {
"company": ["Company", "name"],
},
},
"Cost Center": {
"columns": ["name", "lft", "rgt"],
"conditions": ["docstatus < 2"],
"order_by": "lft",
},
"GL Entry": {
"columns": [
"name",
"account",
"posting_date",
"cost_center",
"debit",
"credit",
"is_opening",
"company",
"voucher_type",
"voucher_no",
"remarks",
],
"order_by": "posting_date, account",
"links": {
"account": ["Account", "name"],
"company": ["Company", "name"],
"cost_center": ["Cost Center", "name"],
},
},
# Stock
"Item": {
"columns": [
"name",
"if(item_name=name, '', item_name) as item_name",
"description",
"item_group as parent_item_group",
"stock_uom",
"brand",
"valuation_method",
],
# "conditions": ["docstatus < 2"],
"order_by": "name",
"links": {"parent_item_group": ["Item Group", "name"], "brand": ["Brand", "name"]},
},
"Item Group": {
"columns": ["name", "parent_item_group"],
# "conditions": ["docstatus < 2"],
"order_by": "lft",
},
"Brand": {"columns": ["name"], "conditions": ["docstatus < 2"], "order_by": "name"},
"Project": {"columns": ["name"], "conditions": ["docstatus < 2"], "order_by": "name"},
"Warehouse": {"columns": ["name"], "conditions": ["docstatus < 2"], "order_by": "name"},
"Stock Ledger Entry": {
"columns": [
"name",
"posting_date",
"posting_time",
"item_code",
"warehouse",
"actual_qty as qty",
"voucher_type",
"voucher_no",
"project",
"incoming_rate as incoming_rate",
"stock_uom",
"serial_no",
"qty_after_transaction",
"valuation_rate",
],
"order_by": "posting_date, posting_time, creation",
"links": {
"item_code": ["Item", "name"],
"warehouse": ["Warehouse", "name"],
"project": ["Project", "name"],
},
"force_index": "posting_sort_index",
},
"Serial No": {
"columns": ["name", "purchase_rate as incoming_rate"],
"conditions": ["docstatus < 2"],
"order_by": "name",
},
"Stock Entry": {
"columns": ["name", "purpose"],
"conditions": ["docstatus=1"],
"order_by": "posting_date, posting_time, name",
},
"Material Request Item": {
"columns": ["item.name as name", "item_code", "warehouse", "(qty - ordered_qty) as qty"],
"from": "`tabMaterial Request Item` item, `tabMaterial Request` main",
"conditions": [
"item.parent = main.name",
"main.docstatus=1",
"main.status != 'Stopped'",
"ifnull(warehouse, '')!=''",
"qty > ordered_qty",
],
"links": {"item_code": ["Item", "name"], "warehouse": ["Warehouse", "name"]},
},
"Purchase Order Item": {
"columns": [
"item.name as name",
"item_code",
"warehouse",
"(qty - received_qty)*conversion_factor as qty",
],
"from": "`tabPurchase Order Item` item, `tabPurchase Order` main",
"conditions": [
"item.parent = main.name",
"main.docstatus=1",
"main.status != 'Stopped'",
"ifnull(warehouse, '')!=''",
"qty > received_qty",
],
"links": {"item_code": ["Item", "name"], "warehouse": ["Warehouse", "name"]},
},
"Sales Order Item": {
"columns": [
"item.name as name",
"item_code",
"(qty - delivered_qty)*conversion_factor as qty",
"warehouse",
],
"from": "`tabSales Order Item` item, `tabSales Order` main",
"conditions": [
"item.parent = main.name",
"main.docstatus=1",
"main.status != 'Stopped'",
"ifnull(warehouse, '')!=''",
"qty > delivered_qty",
],
"links": {"item_code": ["Item", "name"], "warehouse": ["Warehouse", "name"]},
},
# Sales
"Customer": {
"columns": [
"name",
"if(customer_name=name, '', customer_name) as customer_name",
"customer_group as parent_customer_group",
"territory as parent_territory",
],
"conditions": ["docstatus < 2"],
"order_by": "name",
"links": {
"parent_customer_group": ["Customer Group", "name"],
"parent_territory": ["Territory", "name"],
},
},
"Customer Group": {
"columns": ["name", "parent_customer_group"],
"conditions": ["docstatus < 2"],
"order_by": "lft",
},
"Territory": {
"columns": ["name", "parent_territory"],
"conditions": ["docstatus < 2"],
"order_by": "lft",
},
"Sales Invoice": {
"columns": ["name", "customer", "posting_date", "company"],
"conditions": ["docstatus=1"],
"order_by": "posting_date",
"links": {"customer": ["Customer", "name"], "company": ["Company", "name"]},
},
"Sales Invoice Item": {
"columns": ["name", "parent", "item_code", "stock_qty as qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {"parent": ["Sales Invoice", "name"], "item_code": ["Item", "name"]},
},
"Sales Order": {
"columns": ["name", "customer", "transaction_date as posting_date", "company"],
"conditions": ["docstatus=1"],
"order_by": "transaction_date",
"links": {"customer": ["Customer", "name"], "company": ["Company", "name"]},
},
"Sales Order Item[Sales Analytics]": {
"columns": ["name", "parent", "item_code", "stock_qty as qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {"parent": ["Sales Order", "name"], "item_code": ["Item", "name"]},
},
"Delivery Note": {
"columns": ["name", "customer", "posting_date", "company"],
"conditions": ["docstatus=1"],
"order_by": "posting_date",
"links": {"customer": ["Customer", "name"], "company": ["Company", "name"]},
},
"Delivery Note Item[Sales Analytics]": {
"columns": ["name", "parent", "item_code", "stock_qty as qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {"parent": ["Delivery Note", "name"], "item_code": ["Item", "name"]},
},
"Supplier": {
"columns": [
"name",
"if(supplier_name=name, '', supplier_name) as supplier_name",
"supplier_group as parent_supplier_group",
],
"conditions": ["docstatus < 2"],
"order_by": "name",
"links": {
"parent_supplier_group": ["Supplier Group", "name"],
},
},
"Supplier Group": {
"columns": ["name", "parent_supplier_group"],
"conditions": ["docstatus < 2"],
"order_by": "name",
},
"Purchase Invoice": {
"columns": ["name", "supplier", "posting_date", "company"],
"conditions": ["docstatus=1"],
"order_by": "posting_date",
"links": {"supplier": ["Supplier", "name"], "company": ["Company", "name"]},
},
"Purchase Invoice Item": {
"columns": ["name", "parent", "item_code", "stock_qty as qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {"parent": ["Purchase Invoice", "name"], "item_code": ["Item", "name"]},
},
"Purchase Order": {
"columns": ["name", "supplier", "transaction_date as posting_date", "company"],
"conditions": ["docstatus=1"],
"order_by": "posting_date",
"links": {"supplier": ["Supplier", "name"], "company": ["Company", "name"]},
},
"Purchase Order Item[Purchase Analytics]": {
"columns": ["name", "parent", "item_code", "stock_qty as qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {"parent": ["Purchase Order", "name"], "item_code": ["Item", "name"]},
},
"Purchase Receipt": {
"columns": ["name", "supplier", "posting_date", "company"],
"conditions": ["docstatus=1"],
"order_by": "posting_date",
"links": {"supplier": ["Supplier", "name"], "company": ["Company", "name"]},
},
"Purchase Receipt Item[Purchase Analytics]": {
"columns": ["name", "parent", "item_code", "stock_qty as qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {"parent": ["Purchase Receipt", "name"], "item_code": ["Item", "name"]},
},
# Support
"Issue": {
"columns": ["name", "status", "creation", "resolution_date", "first_responded_on"],
"conditions": ["docstatus < 2"],
"order_by": "creation",
},
# Manufacturing
"Work Order": {
"columns": [
"name",
"status",
"creation",
"planned_start_date",
"planned_end_date",
"status",
"actual_start_date",
"actual_end_date",
"modified",
],
"conditions": ["docstatus = 1"],
"order_by": "creation",
},
# Medical
"Patient": {
"columns": [
"name",
"creation",
"owner",
"if(patient_name=name, '', patient_name) as patient_name",
],
"conditions": ["docstatus < 2"],
"order_by": "name",
"links": {"owner": ["User", "name"]},
},
"Patient Appointment": {
"columns": [
"name",
"appointment_type",
"patient",
"practitioner",
"appointment_date",
"department",
"status",
"company",
],
"order_by": "name",
"links": {
"practitioner": ["Healthcare Practitioner", "name"],
"appointment_type": ["Appointment Type", "name"],
},
},
"Healthcare Practitioner": {
"columns": ["name", "department"],
"order_by": "name",
"links": {
"department": ["Department", "name"],
},
},
"Appointment Type": {"columns": ["name"], "order_by": "name"},
"Medical Department": {"columns": ["name"], "order_by": "name"},
}

View File

@@ -60,7 +60,7 @@ def update_youtube_data():
"Video Settings", "Video Settings", ["enable_youtube_tracking", "frequency"]
)
if not enable_youtube_tracking:
if not frappe.utils.cint(enable_youtube_tracking):
return
frequency = get_frequency(frequency)