mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-19 04:59:18 +00:00
[feature] [refactor] Shipping Rule for Buying + Refactor (#11628)
* Shipping rule for Buying * [refactor] shipping rule
This commit is contained in:
@@ -299,6 +299,27 @@ class AccountsController(TransactionBase):
|
||||
"allocated_amount": flt(d.amount) if d.against_order else 0
|
||||
})
|
||||
|
||||
def apply_shipping_rule(self):
|
||||
if self.shipping_rule:
|
||||
shipping_rule = frappe.get_doc("Shipping Rule", self.shipping_rule)
|
||||
shipping_rule.apply(self)
|
||||
self.calculate_taxes_and_totals()
|
||||
|
||||
def get_shipping_address(self):
|
||||
'''Returns Address object from shipping address fields if present'''
|
||||
|
||||
# shipping address fields can be `shipping_address_name` or `shipping_address`
|
||||
# try getting value from both
|
||||
|
||||
for fieldname in ('shipping_address_name', 'shipping_address'):
|
||||
shipping_field = self.meta.get_field(fieldname)
|
||||
if shipping_field and shipping_field.fieldtype == 'Link':
|
||||
if self.get(fieldname):
|
||||
return frappe.get_doc('Address', self.get(fieldname))
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
def get_advance_entries(self, include_unallocated=True):
|
||||
if self.doctype == "Sales Invoice":
|
||||
party_account = self.debit_to
|
||||
|
||||
@@ -420,4 +420,5 @@ class BuyingController(StockController):
|
||||
if d.schedule_date and getdate(d.schedule_date) < getdate(self.transaction_date):
|
||||
frappe.throw(_("Expected Date cannot be before Transaction Date"))
|
||||
else:
|
||||
frappe.throw(_("Please enter Schedule Date"))
|
||||
frappe.throw(_("Please enter Schedule Date"))
|
||||
|
||||
|
||||
@@ -66,38 +66,6 @@ class SellingController(StockController):
|
||||
self.set_price_list_currency("Selling")
|
||||
self.set_missing_item_details(for_validate=for_validate)
|
||||
|
||||
def apply_shipping_rule(self):
|
||||
if self.shipping_rule:
|
||||
shipping_rule = frappe.get_doc("Shipping Rule", self.shipping_rule)
|
||||
value = self.base_net_total
|
||||
|
||||
# TODO
|
||||
# shipping rule calculation based on item's net weight
|
||||
|
||||
shipping_amount = 0.0
|
||||
for condition in shipping_rule.get("conditions"):
|
||||
if not condition.to_value or (flt(condition.from_value) <= value <= flt(condition.to_value)):
|
||||
shipping_amount = condition.shipping_amount
|
||||
break
|
||||
|
||||
shipping_charge = {
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"charge_type": "Actual",
|
||||
"account_head": shipping_rule.account,
|
||||
"cost_center": shipping_rule.cost_center
|
||||
}
|
||||
|
||||
existing_shipping_charge = self.get("taxes", filters=shipping_charge)
|
||||
if existing_shipping_charge:
|
||||
# take the last record found
|
||||
existing_shipping_charge[-1].tax_amount = shipping_amount
|
||||
else:
|
||||
shipping_charge["tax_amount"] = shipping_amount
|
||||
shipping_charge["description"] = shipping_rule.label
|
||||
self.append("taxes", shipping_charge)
|
||||
|
||||
self.calculate_taxes_and_totals()
|
||||
|
||||
def remove_shipping_charge(self):
|
||||
if self.shipping_rule:
|
||||
shipping_rule = frappe.get_doc("Shipping Rule", self.shipping_rule)
|
||||
|
||||
@@ -233,7 +233,8 @@ class calculate_taxes_and_totals(object):
|
||||
# if tax/charges is for deduction, multiply by -1
|
||||
if getattr(tax, "category", None):
|
||||
tax_amount = 0.0 if (tax.category == "Valuation") else tax_amount
|
||||
tax_amount *= -1.0 if (tax.add_deduct_tax == "Deduct") else 1.0
|
||||
if self.doc.doctype in ["Purchase Order", "Purchase Invoice", "Purchase Receipt", "Supplier Quotation"]:
|
||||
tax_amount *= -1.0 if (tax.add_deduct_tax == "Deduct") else 1.0
|
||||
return tax_amount
|
||||
|
||||
def set_cumulative_total(self, row_idx, tax):
|
||||
|
||||
Reference in New Issue
Block a user