fix: disable pricing rules for internal transfers (#31034)
* fix: disable pricing rules for internal transfers * fix: only apply validation on internal transfers Co-authored-by: Marica <maricadsouza221197@gmail.com> * fix: internal_party_field undefined Co-authored-by: Marica <maricadsouza221197@gmail.com>
This commit is contained in:
parent
06c036f49f
commit
3714e36b44
@ -148,6 +148,7 @@ class AccountsController(TransactionBase):
|
||||
|
||||
self.validate_inter_company_reference()
|
||||
|
||||
self.disable_pricing_rule_on_internal_transfer()
|
||||
self.set_incoming_rate()
|
||||
|
||||
if self.meta.get_field("currency"):
|
||||
@ -382,6 +383,14 @@ class AccountsController(TransactionBase):
|
||||
msg += _("Please create purchase from internal sale or delivery document itself")
|
||||
frappe.throw(msg, title=_("Internal Sales Reference Missing"))
|
||||
|
||||
def disable_pricing_rule_on_internal_transfer(self):
|
||||
if not self.get("ignore_pricing_rule") and self.is_internal_transfer():
|
||||
self.ignore_pricing_rule = 1
|
||||
frappe.msgprint(
|
||||
_("Disabled pricing rules since this {} is an internal transfer").format(self.doctype),
|
||||
alert=1,
|
||||
)
|
||||
|
||||
def validate_due_date(self):
|
||||
if self.get("is_pos"):
|
||||
return
|
||||
@ -1738,6 +1747,8 @@ class AccountsController(TransactionBase):
|
||||
internal_party_field = "is_internal_customer"
|
||||
elif self.doctype in ("Purchase Invoice", "Purchase Receipt", "Purchase Order"):
|
||||
internal_party_field = "is_internal_supplier"
|
||||
else:
|
||||
return False
|
||||
|
||||
if self.get(internal_party_field) and (self.represents_company == self.company):
|
||||
return True
|
||||
|
@ -1007,6 +1007,7 @@ class TestDeliveryNote(FrappeTestCase):
|
||||
customer = create_internal_customer(represents_company=company)
|
||||
rate = 42
|
||||
|
||||
# Create item price and pricing rule
|
||||
frappe.get_doc(
|
||||
{
|
||||
"item_code": item,
|
||||
@ -1016,6 +1017,25 @@ class TestDeliveryNote(FrappeTestCase):
|
||||
}
|
||||
).insert()
|
||||
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Pricing Rule",
|
||||
"title": frappe.generate_hash(),
|
||||
"apply_on": "Item Code",
|
||||
"price_or_product_discount": "Price",
|
||||
"selling": 1,
|
||||
"company": company,
|
||||
"margin_type": "Percentage",
|
||||
"margin_rate_or_amount": 10,
|
||||
"apply_discount_on": "Grand Total",
|
||||
"items": [
|
||||
{
|
||||
"item_code": item,
|
||||
}
|
||||
],
|
||||
}
|
||||
).insert()
|
||||
|
||||
make_stock_entry(target=warehouse, qty=5, basic_rate=rate, item_code=item)
|
||||
dn = create_delivery_note(
|
||||
item_code=item,
|
||||
@ -1025,12 +1045,14 @@ class TestDeliveryNote(FrappeTestCase):
|
||||
rate=500,
|
||||
warehouse=warehouse,
|
||||
target_warehouse=target,
|
||||
ignore_pricing_rule=0,
|
||||
do_not_save=True,
|
||||
do_not_submit=True,
|
||||
)
|
||||
|
||||
self.assertEqual(dn.items[0].rate, 500) # haven't saved yet
|
||||
dn.save()
|
||||
self.assertEqual(dn.ignore_pricing_rule, 1)
|
||||
|
||||
# rate should reset to incoming rate
|
||||
self.assertEqual(dn.items[0].rate, rate)
|
||||
|
Loading…
x
Reference in New Issue
Block a user