[cart] create quotation on checkout

This commit is contained in:
Anand Doshi
2013-06-14 17:44:03 +05:30
parent 37982a6a1f
commit abc100302c
17 changed files with 306 additions and 59 deletions

View File

@@ -17,8 +17,9 @@
from __future__ import unicode_literals
import webnotes
from webnotes import _, msgprint
from webnotes.utils import flt, cint
from webnotes.utils import flt, cint, today
from setup.utils import get_company_currency, get_price_list_currency
from accounts.utils import get_fiscal_year
from utilities.transaction_base import TransactionBase, validate_conversion_rate
import json
@@ -36,6 +37,13 @@ class AccountsController(TransactionBase):
self.validate_value("grand_total", ">=", 0)
self.set_total_in_words()
def set_missing_values(self, for_validate=False):
for fieldname in ["posting_date", "transaction_date"]:
if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname):
self.doc.fields[fieldname] = today()
if not self.doc.fiscal_year:
self.doc.fiscal_year = get_fiscal_year(self.doc.fields[fieldname])[0]
def set_price_list_currency(self, buying_or_selling):
# TODO - change this, since price list now has only one currency allowed
if self.meta.get_field("price_list_name") and self.doc.price_list_name and \
@@ -45,6 +53,14 @@ class AccountsController(TransactionBase):
"buying_or_selling": buying_or_selling
}))
if not self.doc.plc_conversion_rate:
self.doc.plc_conversion_rate = flt(webnotes.conn.get_value("Price List",
self.doc.price_list_name, "conversion_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}):

View File

@@ -28,11 +28,8 @@ class WrongWarehouseCompany(Exception): pass
class BuyingController(StockController):
def onload_post_render(self):
self.set_price_list_currency("buying")
# contact, address, item details
self.set_missing_values()
self.set_taxes("Purchase Taxes and Charges", "purchase_tax_details", "purchase_other_charges")
def validate(self):
@@ -41,6 +38,10 @@ class BuyingController(StockController):
self.validate_warehouse_belongs_to_company()
def set_missing_values(self, for_validate=False):
super(BuyingController, self).set_missing_values(for_validate)
self.set_price_list_currency("Buying")
# set contact and address details for supplier, if they are not mentioned
if self.doc.supplier and not (self.doc.contact_person and self.doc.supplier_address):
for fieldname, val in self.get_default_address_and_contact("supplier").items():

View File

@@ -25,21 +25,41 @@ from controllers.stock_controller import StockController
class SellingController(StockController):
def onload_post_render(self):
self.set_price_list_currency("selling")
# contact, address, item details and pos details (if applicable)
self.set_missing_values()
self.set_taxes("Sales Taxes and Charges", "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
if self.doc.customer and 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.fields.get(fieldname) and self.meta.get_field(fieldname):
self.doc.fields[fieldname] = val
self.set_missing_lead_customer_details()
self.set_missing_item_details(get_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.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
def get_other_charges(self):
self.doclist = self.doc.clear_table(self.doclist, "other_charges")
@@ -241,7 +261,7 @@ class SellingController(StockController):
" " + _("should be 100%"), raise_exception=True)
def validate_order_type(self):
valid_types = ["Sales", "Maintenance"]
valid_types = ["Sales", "Maintenance", "Shopping Cart"]
if self.doc.order_type not in valid_types:
msgprint(_(self.meta.get_label("order_type")) + " " +
_("must be one of") + ": " + comma_or(valid_types),