mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-24 23:49:19 +00:00
[webshop] shopping cart settings, update price list, taxes and shipping rule on change of address, apply defaults on creation of fresh quotation
This commit is contained in:
@@ -55,14 +55,18 @@ class AccountsController(TransactionBase):
|
||||
|
||||
if self.doc.price_list_currency:
|
||||
if not self.doc.plc_conversion_rate:
|
||||
exchange = self.doc.price_list_currency + "-" + get_company_currency(self.doc.company)
|
||||
self.doc.plc_conversion_rate = flt(webnotes.conn.get_value("Currency Exchange",
|
||||
exchange, "exchange_rate"))
|
||||
company_currency = get_company_currency(self.doc.company)
|
||||
if self.doc.price_list_currency == company_currency:
|
||||
self.doc.plc_conversion_rate = 1.0
|
||||
else:
|
||||
exchange = self.doc.price_list_currency + "-" + company_currency
|
||||
self.doc.plc_conversion_rate = flt(webnotes.conn.get_value("Currency Exchange",
|
||||
exchange, "exchange_rate"))
|
||||
|
||||
if not self.doc.currency:
|
||||
self.doc.currency = self.doc.price_list_currency
|
||||
self.doc.conversion_rate = self.doc.plc_conversion_rate
|
||||
|
||||
|
||||
def set_missing_item_details(self, get_item_details):
|
||||
"""set missing item values"""
|
||||
for item in self.doclist.get({"parentfield": self.fname}):
|
||||
@@ -71,34 +75,44 @@ class AccountsController(TransactionBase):
|
||||
ret = get_item_details(args)
|
||||
for fieldname, value in ret.items():
|
||||
if self.meta.get_field(fieldname, parentfield=self.fname) and \
|
||||
item.fields.get(fieldname) is None:
|
||||
item.fields.get(fieldname) is None and value is not None:
|
||||
item.fields[fieldname] = value
|
||||
|
||||
def set_taxes(self, tax_doctype, tax_parentfield, tax_master_field):
|
||||
def set_taxes(self, tax_parentfield, tax_master_field):
|
||||
if not self.meta.get_field(tax_parentfield):
|
||||
return
|
||||
|
||||
tax_master_doctype = self.meta.get_field(tax_master_field).options
|
||||
|
||||
if not self.doclist.get({"parentfield": tax_parentfield}):
|
||||
if not self.doc.fields.get(tax_master_field):
|
||||
# get the default tax master
|
||||
self.doc.fields[tax_master_field] = \
|
||||
webnotes.conn.get_value(tax_doctype + " Master", {"is_default": 1})
|
||||
|
||||
if self.doc.fields.get(tax_master_field):
|
||||
from webnotes.model import default_fields
|
||||
tax_master = webnotes.bean(tax_doctype + " Master", self.doc.fields.get(tax_master_field))
|
||||
|
||||
for i, tax in enumerate(tax_master.doclist.get({"parentfield": tax_parentfield})):
|
||||
for fieldname in default_fields:
|
||||
tax.fields[fieldname] = None
|
||||
webnotes.conn.get_value(tax_master_doctype, {"is_default": 1})
|
||||
|
||||
tax.fields.update({
|
||||
"doctype": tax_doctype,
|
||||
"parentfield": tax_parentfield,
|
||||
"idx": i+1
|
||||
})
|
||||
|
||||
self.doclist.append(tax)
|
||||
self.append_taxes_from_master(tax_parentfield, tax_master_field, tax_master_doctype)
|
||||
|
||||
def append_taxes_from_master(self, tax_parentfield, tax_master_field, tax_master_doctype=None):
|
||||
if self.doc.fields.get(tax_master_field):
|
||||
if not tax_master_doctype:
|
||||
tax_master_doctype = self.meta.get_field(tax_master_field).options
|
||||
|
||||
tax_doctype = self.meta.get_field(tax_parentfield).options
|
||||
|
||||
from webnotes.model import default_fields
|
||||
tax_master = webnotes.bean(tax_master_doctype, self.doc.fields.get(tax_master_field))
|
||||
|
||||
for i, tax in enumerate(tax_master.doclist.get({"parentfield": tax_parentfield})):
|
||||
for fieldname in default_fields:
|
||||
tax.fields[fieldname] = None
|
||||
|
||||
tax.fields.update({
|
||||
"doctype": tax_doctype,
|
||||
"parentfield": tax_parentfield,
|
||||
"idx": i+1
|
||||
})
|
||||
|
||||
self.doclist.append(tax)
|
||||
|
||||
def calculate_taxes_and_totals(self):
|
||||
self.doc.conversion_rate = flt(self.doc.conversion_rate)
|
||||
|
||||
@@ -30,7 +30,7 @@ class BuyingController(StockController):
|
||||
def onload_post_render(self):
|
||||
# contact, address, item details
|
||||
self.set_missing_values()
|
||||
self.set_taxes("Purchase Taxes and Charges", "purchase_tax_details", "purchase_other_charges")
|
||||
self.set_taxes("purchase_tax_details", "purchase_other_charges")
|
||||
|
||||
def validate(self):
|
||||
super(BuyingController, self).validate()
|
||||
@@ -55,7 +55,7 @@ class BuyingController(StockController):
|
||||
|
||||
def get_purchase_tax_details(self):
|
||||
self.doclist = self.doc.clear_table(self.doclist, "purchase_tax_details")
|
||||
self.set_taxes("Purchase Taxes and Charges", "purchase_tax_details", "purchase_other_charges")
|
||||
self.set_taxes("purchase_tax_details", "purchase_other_charges")
|
||||
|
||||
def validate_warehouse_belongs_to_company(self):
|
||||
for warehouse, company in webnotes.conn.get_values("Warehouse",
|
||||
|
||||
@@ -28,48 +28,62 @@ class SellingController(StockController):
|
||||
# contact, address, item details and pos details (if applicable)
|
||||
self.set_missing_values()
|
||||
|
||||
self.set_taxes("Sales Taxes and Charges", "other_charges", "charge")
|
||||
self.set_taxes("other_charges", "charge")
|
||||
|
||||
def set_missing_values(self, for_validate=False):
|
||||
super(SellingController, self).set_missing_values(for_validate)
|
||||
|
||||
self.set_price_list_currency("Selling")
|
||||
|
||||
# set contact and address details for customer, if they are not mentioned
|
||||
self.set_missing_lead_customer_details()
|
||||
|
||||
self.set_missing_item_details(get_item_details)
|
||||
|
||||
self.set_price_list_and_item_details()
|
||||
|
||||
def set_missing_lead_customer_details(self):
|
||||
if self.doc.customer:
|
||||
if not (self.doc.contact_person and self.doc.customer_address):
|
||||
for fieldname, val in self.get_default_address_and_contact("customer").items():
|
||||
if not (self.doc.contact_person and self.doc.customer_address and self.doc.customer_name):
|
||||
for fieldname, val in self.get_customer_defaults().items():
|
||||
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
|
||||
self.doc.fields[fieldname] = val
|
||||
|
||||
customer_fetch = webnotes.conn.get_value("Customer", self.doc.customer,
|
||||
['customer_name', 'customer_group', 'territory'], as_dict=True)
|
||||
for fieldname in ['customer_name', 'customer_group', 'territory']:
|
||||
if not self.doc.fields.get(fieldname):
|
||||
self.doc.fields[fieldname] = customer_fetch[fieldname]
|
||||
|
||||
elif self.doc.lead:
|
||||
lead_fetch = webnotes.conn.get_value("Lead", self.doc.lead,
|
||||
['company_name', 'lead_name', 'territory'], as_dict=True)
|
||||
if not self.doc.customer_name:
|
||||
self.doc.customer_name = lead_fetch.company_name or lead_fetch.lead_name
|
||||
if not self.doc.territory:
|
||||
self.doc.territory = lead_fetch.territory
|
||||
|
||||
if not (self.doc.customer_address and self.doc.customer_name and \
|
||||
self.doc.contact_display):
|
||||
for fieldname, val in self.get_lead_defaults().items():
|
||||
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
|
||||
self.doc.fields[fieldname] = val
|
||||
|
||||
def set_price_list_and_item_details(self):
|
||||
self.set_price_list_currency("Selling")
|
||||
self.set_missing_item_details(get_item_details)
|
||||
|
||||
def get_other_charges(self):
|
||||
self.doclist = self.doc.clear_table(self.doclist, "other_charges")
|
||||
self.set_taxes("Sales Taxes and Charges", "other_charges", "charge")
|
||||
self.set_taxes("other_charges", "charge")
|
||||
|
||||
def set_customer_defaults(self):
|
||||
self.get_default_customer_address()
|
||||
|
||||
if self.meta.get_field("shipping_address"):
|
||||
self.doc.fields.update(self.get_shipping_address(self.doc.customer))
|
||||
def apply_shipping_rule(self):
|
||||
if self.doc.shipping_rule:
|
||||
shipping_rule = webnotes.bean("Shipping Rule", self.doc.shipping_rule)
|
||||
value = self.doc.net_total
|
||||
|
||||
# TODO
|
||||
# shipping rule calculation based on item's net weight
|
||||
|
||||
shipping_amount = 0.0
|
||||
for condition in shipping_rule.doclist.get({"parentfield": "shipping_rule_conditions"}):
|
||||
if not condition.to_value or (flt(condition.from_value) <= value <= flt(condition.to_value)):
|
||||
shipping_amount = condition.shipping_amount
|
||||
break
|
||||
|
||||
if shipping_amount:
|
||||
self.doclist.append({
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"parentfield": "other_charges",
|
||||
"charge_type": "Actual",
|
||||
"account_head": shipping_rule.doc.account,
|
||||
"cost_center": shipping_rule.doc.cost_center,
|
||||
"description": shipping_rule.doc.label,
|
||||
"rate": shipping_amount
|
||||
})
|
||||
|
||||
def set_total_in_words(self):
|
||||
from webnotes.utils import money_in_words
|
||||
|
||||
Reference in New Issue
Block a user