[selling] [calculations] client side calculations, cleanup, patch fixes
This commit is contained in:
parent
b5aa8da0dd
commit
f309613a7d
@ -54,10 +54,8 @@ erpnext.buying.PurchaseInvoiceController = erpnext.buying.BuyingController.exten
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var new_cscript = new erpnext.buying.PurchaseInvoiceController({frm: cur_frm});
|
|
||||||
|
|
||||||
// for backward compatibility: combine new and previous states
|
// for backward compatibility: combine new and previous states
|
||||||
$.extend(cur_frm.cscript, new_cscript);
|
$.extend(cur_frm.cscript, new erpnext.buying.PurchaseInvoiceController({frm: cur_frm}));
|
||||||
|
|
||||||
|
|
||||||
cur_frm.cscript.onload = function(doc,dt,dn) {
|
cur_frm.cscript.onload = function(doc,dt,dn) {
|
||||||
|
@ -26,48 +26,62 @@ wn.require('app/selling/doctype/sales_common/sales_common.js');
|
|||||||
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
|
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
|
||||||
wn.require('app/utilities/doctype/sms_control/sms_control.js');
|
wn.require('app/utilities/doctype/sms_control/sms_control.js');
|
||||||
|
|
||||||
// On Load
|
erpnext.selling.SalesInvoiceController = erpnext.selling.SellingController.extend({
|
||||||
// -------
|
onload: function() {
|
||||||
cur_frm.cscript.onload = function(doc,dt,dn) {
|
this._super();
|
||||||
cur_frm.cscript.manage_rounded_total();
|
|
||||||
if(!doc.customer && doc.debit_to) wn.meta.get_docfield(dt, 'debit_to', dn).print_hide = 0;
|
// show debit_to in print format
|
||||||
if (doc.__islocal) {
|
if(!this.frm.doc.customer && this.frm.doc.debit_to) {
|
||||||
if(!doc.due_date) set_multiple(dt,dn,{due_date:get_today()});
|
this.frm.set_df_property("debit_to", "print_hide", 0);
|
||||||
if(!doc.posting_date) set_multiple(dt,dn,{posting_date:get_today()});
|
}
|
||||||
if(!doc.currency && sys_defaults.currency) set_multiple(dt,dn,{currency:sys_defaults.currency});
|
},
|
||||||
if(!doc.price_list_currency) set_multiple(dt, dn, {price_list_currency: doc.currency, plc_conversion_rate: 1});
|
|
||||||
|
refresh: function(doc, dt, dn) {
|
||||||
|
this._super();
|
||||||
|
|
||||||
|
cur_frm.cscript.is_opening(doc, dt, dn);
|
||||||
|
|
||||||
}
|
// Show / Hide button
|
||||||
}
|
cur_frm.clear_custom_buttons();
|
||||||
|
// if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, dt, dn);
|
||||||
|
|
||||||
cur_frm.cscript.onload_post_render = function(doc, dt, dn) {
|
if(doc.docstatus==1) {
|
||||||
var callback = function(doc, dt, dn) {
|
cur_frm.add_custom_button('View Ledger', cur_frm.cscript.view_ledger_entry);
|
||||||
// called from mapper, update the account names for items and customer
|
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
|
||||||
var callback2 = function(doc, dt, dn) {
|
|
||||||
if(doc.customer && doc.__islocal) {
|
if(doc.is_pos==1 && doc.update_stock!=1)
|
||||||
$c_obj(make_doclist(doc.doctype,doc.name),
|
cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
|
||||||
'load_default_accounts','',
|
|
||||||
function(r,rt) {
|
if(doc.outstanding_amount!=0)
|
||||||
refresh_field('entries');
|
cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript.make_bank_voucher);
|
||||||
cur_frm.cscript.customer(doc,dt,dn,onload=true);
|
}
|
||||||
}
|
cur_frm.cscript.hide_fields(doc, dt, dn);
|
||||||
);
|
},
|
||||||
|
|
||||||
|
is_pos: function() {
|
||||||
|
if(cint(this.frm.doc.is_pos)) {
|
||||||
|
if(!this.frm.doc.company) {
|
||||||
|
this.frm.set_value("is_pos", 0);
|
||||||
|
msgprint(wn._("Please specify Company to proceed"));
|
||||||
|
} else {
|
||||||
|
var me = this;
|
||||||
|
this.frm.call({
|
||||||
|
doc: me.frm.doc,
|
||||||
|
method: "set_missing_values",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// defined in sales_common.js
|
|
||||||
var callback1 = function(doc, dt, dn) {
|
|
||||||
//for previously created sales invoice, set required field related to pos
|
|
||||||
cur_frm.cscript.update_item_details(doc, dt, dn, callback2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(doc.is_pos ==1) cur_frm.cscript.is_pos(doc, dt, dn,callback1);
|
// TODO toggle display of fields
|
||||||
else cur_frm.cscript.update_item_details(doc, dt, dn, callback2);
|
},
|
||||||
}
|
|
||||||
|
debit_to: function() {
|
||||||
cur_frm.cscript.hide_price_list_currency(doc, dt, dn, callback);
|
this.customer();
|
||||||
|
},
|
||||||
}
|
});
|
||||||
|
|
||||||
|
// for backward compatibility: combine new and previous states
|
||||||
|
$.extend(cur_frm.cscript, new erpnext.selling.SalesInvoiceController({frm: cur_frm}));
|
||||||
|
|
||||||
// Hide Fields
|
// Hide Fields
|
||||||
// ------------
|
// ------------
|
||||||
@ -104,50 +118,6 @@ cur_frm.cscript.hide_fields = function(doc, cdt, cdn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Refresh
|
|
||||||
// -------
|
|
||||||
cur_frm.cscript.refresh = function(doc, dt, dn) {
|
|
||||||
cur_frm.cscript.is_opening(doc, dt, dn);
|
|
||||||
erpnext.hide_naming_series();
|
|
||||||
|
|
||||||
// Show / Hide button
|
|
||||||
cur_frm.clear_custom_buttons();
|
|
||||||
if (!cur_frm.cscript.is_onload) cur_frm.cscript.hide_price_list_currency(doc, dt, dn);
|
|
||||||
|
|
||||||
if(doc.docstatus==1) {
|
|
||||||
cur_frm.add_custom_button('View Ledger', cur_frm.cscript.view_ledger_entry);
|
|
||||||
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
|
|
||||||
|
|
||||||
if(doc.is_pos==1 && doc.update_stock!=1)
|
|
||||||
cur_frm.add_custom_button('Make Delivery', cur_frm.cscript['Make Delivery Note']);
|
|
||||||
|
|
||||||
if(doc.outstanding_amount!=0)
|
|
||||||
cur_frm.add_custom_button('Make Payment Entry', cur_frm.cscript.make_bank_voucher);
|
|
||||||
}
|
|
||||||
cur_frm.cscript.hide_fields(doc, dt, dn);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//fetch retail transaction related fields
|
|
||||||
//--------------------------------------------
|
|
||||||
cur_frm.cscript.is_pos = function(doc,dt,dn,callback){
|
|
||||||
cur_frm.cscript.hide_fields(doc, dt, dn);
|
|
||||||
if(doc.is_pos == 1){
|
|
||||||
if (!doc.company) {
|
|
||||||
msgprint("Please select company to proceed");
|
|
||||||
doc.is_pos = 0;
|
|
||||||
refresh_field('is_pos');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var callback1 = function(r,rt){
|
|
||||||
if(callback) callback(doc, dt, dn);
|
|
||||||
cur_frm.refresh();
|
|
||||||
}
|
|
||||||
$c_obj(make_doclist(dt,dn),'set_pos_fields','',callback1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cur_frm.cscript.mode_of_payment = function(doc) {
|
cur_frm.cscript.mode_of_payment = function(doc) {
|
||||||
cur_frm.call({
|
cur_frm.call({
|
||||||
method: "get_bank_cash_account",
|
method: "get_bank_cash_account",
|
||||||
@ -168,66 +138,10 @@ cur_frm.cscript.warehouse = function(doc, cdt , cdn) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Customer
|
|
||||||
cur_frm.cscript.customer = function(doc,dt,dn,onload) {
|
|
||||||
cur_frm.toggle_display("contact_section", doc.customer);
|
|
||||||
|
|
||||||
var pl = doc.price_list_name;
|
|
||||||
var callback = function(r,rt) {
|
|
||||||
var callback2 = function(doc, dt, dn) {
|
|
||||||
doc = locals[dt][dn];
|
|
||||||
if(doc.debit_to && doc.posting_date){
|
|
||||||
get_server_fields('get_cust_and_due_date','','',doc,dt,dn,1,
|
|
||||||
function(doc, dt, dn) {
|
|
||||||
cur_frm.refresh();
|
|
||||||
if (!onload && (pl != doc.price_list_name)) cur_frm.cscript.price_list_name(doc, dt, dn);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
|
||||||
get_server_fields('get_debit_to','','',doc, dt, dn, 0, callback2);
|
|
||||||
}
|
|
||||||
var args = onload ? 'onload':''
|
|
||||||
if(doc.customer) $c_obj(make_doclist(doc.doctype, doc.name), 'get_default_customer_address', args, callback);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
|
cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {
|
||||||
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
|
if(doc.customer) get_server_fields('get_customer_address', JSON.stringify({customer: doc.customer, address: doc.customer_address, contact: doc.contact_person}),'', doc, dt, dn, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set Due Date = posting date + credit days
|
|
||||||
cur_frm.cscript.debit_to = function(doc,dt,dn) {
|
|
||||||
|
|
||||||
var callback2 = function(r,rt) {
|
|
||||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
|
||||||
cur_frm.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
var callback = function(r,rt) {
|
|
||||||
var doc = locals[cur_frm.doctype][cur_frm.docname];
|
|
||||||
if(doc.customer) $c_obj(make_doclist(dt,dn), 'get_default_customer_address', '', callback2);
|
|
||||||
cur_frm.toggle_display("contact_section", doc.customer);
|
|
||||||
|
|
||||||
cur_frm.refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(doc.debit_to && doc.posting_date){
|
|
||||||
get_server_fields('get_cust_and_due_date','','',doc,dt,dn,1,callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//refresh advance amount
|
|
||||||
//-------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
cur_frm.cscript.write_off_outstanding_amount_automatically = function(doc) {
|
cur_frm.cscript.write_off_outstanding_amount_automatically = function(doc) {
|
||||||
if (doc.write_off_outstanding_amount_automatically == 1)
|
if (doc.write_off_outstanding_amount_automatically == 1)
|
||||||
doc.write_off_amount = flt(doc.grand_total) - flt(doc.paid_amount);
|
doc.write_off_amount = flt(doc.grand_total) - flt(doc.paid_amount);
|
||||||
@ -244,9 +158,6 @@ cur_frm.cscript.write_off_amount = function(doc) {
|
|||||||
cur_frm.cscript.write_off_outstanding_amount_automatically(doc);
|
cur_frm.cscript.write_off_outstanding_amount_automatically(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Set debit and credit to zero on adding new row
|
|
||||||
//----------------------------------------------
|
|
||||||
cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){
|
cur_frm.fields_dict['entries'].grid.onrowadd = function(doc, cdt, cdn){
|
||||||
|
|
||||||
cl = getchildren('Sales Invoice Item', doc.name, cur_frm.cscript.fname, doc.doctype);
|
cl = getchildren('Sales Invoice Item', doc.name, cur_frm.cscript.fname, doc.doctype);
|
||||||
|
@ -41,7 +41,6 @@ class DocType(SellingController):
|
|||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
super(DocType, self).validate()
|
super(DocType, self).validate()
|
||||||
self.fetch_missing_values()
|
|
||||||
self.validate_posting_time()
|
self.validate_posting_time()
|
||||||
self.so_dn_required()
|
self.so_dn_required()
|
||||||
self.validate_proj_cust()
|
self.validate_proj_cust()
|
||||||
@ -50,7 +49,6 @@ class DocType(SellingController):
|
|||||||
sales_com_obj.check_active_sales_items(self)
|
sales_com_obj.check_active_sales_items(self)
|
||||||
sales_com_obj.check_conversion_rate(self)
|
sales_com_obj.check_conversion_rate(self)
|
||||||
sales_com_obj.validate_max_discount(self, 'entries')
|
sales_com_obj.validate_max_discount(self, 'entries')
|
||||||
sales_com_obj.get_allocated_sum(self)
|
|
||||||
sales_com_obj.validate_fiscal_year(self.doc.fiscal_year,
|
sales_com_obj.validate_fiscal_year(self.doc.fiscal_year,
|
||||||
self.doc.posting_date,'Posting Date')
|
self.doc.posting_date,'Posting Date')
|
||||||
self.validate_customer()
|
self.validate_customer()
|
||||||
@ -134,25 +132,16 @@ class DocType(SellingController):
|
|||||||
self.validate_recurring_invoice()
|
self.validate_recurring_invoice()
|
||||||
self.convert_to_recurring()
|
self.convert_to_recurring()
|
||||||
|
|
||||||
def fetch_missing_values(self):
|
def set_missing_values(self, for_validate=False):
|
||||||
# fetch contact and address details for customer, if they are not mentioned
|
super(DocType, self).set_missing_values(for_validate)
|
||||||
if not (self.doc.contact_person and self.doc.customer_address):
|
self.set_pos_fields(for_validate)
|
||||||
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
|
|
||||||
|
|
||||||
# fetch missing item values
|
|
||||||
for item in self.doclist.get({"parentfield": "entries"}):
|
|
||||||
if item.fields.get("item_code"):
|
|
||||||
ret = get_obj('Sales Common').get_item_details(item.fields, self)
|
|
||||||
for fieldname, value in ret.items():
|
|
||||||
if self.meta.get_field(fieldname, parentfield="entries") and \
|
|
||||||
not item.fields.get(fieldname):
|
|
||||||
item.fields[fieldname] = value
|
|
||||||
|
|
||||||
# fetch pos details, if they are not fetched
|
def set_customer_defaults(self):
|
||||||
if cint(self.doc.is_pos):
|
# TODO cleanup these methods
|
||||||
self.set_pos_fields(for_validate=True)
|
self.doc.fields.update(self.get_debit_to())
|
||||||
|
self.get_cust_and_due_date()
|
||||||
|
|
||||||
|
super(DocType, self).set_customer_defaults()
|
||||||
|
|
||||||
def update_time_log_batch(self, sales_invoice):
|
def update_time_log_batch(self, sales_invoice):
|
||||||
for d in self.doclist.get({"doctype":"Sales Invoice Item"}):
|
for d in self.doclist.get({"doctype":"Sales Invoice Item"}):
|
||||||
@ -173,10 +162,11 @@ class DocType(SellingController):
|
|||||||
"""Set retail related fields from pos settings"""
|
"""Set retail related fields from pos settings"""
|
||||||
if cint(self.doc.is_pos) != 1:
|
if cint(self.doc.is_pos) != 1:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
from selling.utils import get_pos_settings, apply_pos_settings
|
||||||
|
pos = get_pos_settings(self.doc.company)
|
||||||
|
|
||||||
if self.pos_settings:
|
if pos:
|
||||||
pos = self.pos_settings[0]
|
|
||||||
|
|
||||||
self.doc.conversion_rate = flt(pos.conversion_rate)
|
self.doc.conversion_rate = flt(pos.conversion_rate)
|
||||||
|
|
||||||
if not self.doc.debit_to:
|
if not self.doc.debit_to:
|
||||||
@ -193,7 +183,7 @@ class DocType(SellingController):
|
|||||||
# set pos values in items
|
# set pos values in items
|
||||||
for item in self.doclist.get({"parentfield": "entries"}):
|
for item in self.doclist.get({"parentfield": "entries"}):
|
||||||
if item.fields.get('item_code'):
|
if item.fields.get('item_code'):
|
||||||
for fieldname, val in self.apply_pos_settings(item.fields).items():
|
for fieldname, val in apply_pos_settings(pos, item.fields).items():
|
||||||
if (not for_validate) or (for_validate and not item.fields.get(fieldname)):
|
if (not for_validate) or (for_validate and not item.fields.get(fieldname)):
|
||||||
item.fields[fieldname] = val
|
item.fields[fieldname] = val
|
||||||
|
|
||||||
@ -203,7 +193,7 @@ class DocType(SellingController):
|
|||||||
|
|
||||||
# fetch charges
|
# fetch charges
|
||||||
if self.doc.charge and not len(self.doclist.get({"parentfield": "other_charges"})):
|
if self.doc.charge and not len(self.doclist.get({"parentfield": "other_charges"})):
|
||||||
self.get_other_charges()
|
self.set_taxes()
|
||||||
|
|
||||||
def get_customer_account(self):
|
def get_customer_account(self):
|
||||||
"""Get Account Head to which amount needs to be Debited based on Customer"""
|
"""Get Account Head to which amount needs to be Debited based on Customer"""
|
||||||
@ -272,86 +262,14 @@ class DocType(SellingController):
|
|||||||
ret = self.get_debit_to()
|
ret = self.get_debit_to()
|
||||||
self.doc.debit_to = ret.get('debit_to')
|
self.doc.debit_to = ret.get('debit_to')
|
||||||
|
|
||||||
|
|
||||||
def load_default_accounts(self):
|
|
||||||
"""
|
|
||||||
Loads default accounts from items, customer when called from mapper
|
|
||||||
"""
|
|
||||||
self.get_income_expense_account('entries')
|
|
||||||
|
|
||||||
|
|
||||||
def get_income_expense_account(self,doctype):
|
|
||||||
for d in getlist(self.doclist, doctype):
|
|
||||||
if d.item_code:
|
|
||||||
item = webnotes.conn.get_value("Item", d.item_code, ["default_income_account",
|
|
||||||
"default_sales_cost_center", "purchase_account"], as_dict=True)
|
|
||||||
d.income_account = item['default_income_account'] or ""
|
|
||||||
d.cost_center = item['default_sales_cost_center'] or ""
|
|
||||||
|
|
||||||
if cint(webnotes.defaults.get_global_default("auto_inventory_accounting")) \
|
|
||||||
and cint(self.doc.is_pos) and cint(self.doc.update_stock):
|
|
||||||
d.expense_account = item['purchase_account'] or ""
|
|
||||||
|
|
||||||
def get_item_details(self, args=None):
|
|
||||||
import json
|
|
||||||
args = args and json.loads(args) or {}
|
|
||||||
if args.get('item_code'):
|
|
||||||
ret = get_obj('Sales Common').get_item_details(args, self)
|
|
||||||
|
|
||||||
if cint(self.doc.is_pos) == 1 and self.pos_settings:
|
|
||||||
ret = self.apply_pos_settings(args, ret)
|
|
||||||
|
|
||||||
return ret
|
|
||||||
|
|
||||||
elif cint(self.doc.is_pos) == 1 and self.pos_settings:
|
|
||||||
for doc in self.doclist.get({"parentfield": "entries"}):
|
|
||||||
if doc.fields.get('item_code'):
|
|
||||||
ret = self.apply_pos_settings(doc.fields)
|
|
||||||
for r in ret:
|
|
||||||
if not doc.fields.get(r):
|
|
||||||
doc.fields[r] = ret[r]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pos_settings(self):
|
def pos_settings(self):
|
||||||
if not hasattr(self, "_pos_settings"):
|
if not hasattr(self, "_pos_settings"):
|
||||||
dtl = webnotes.conn.sql("""select * from `tabPOS Setting` where user = %s
|
from selling.utils import get_pos_settings
|
||||||
and company = %s""", (webnotes.session['user'], self.doc.company), as_dict=1)
|
self._pos_settings = get_pos_settings({"company": self.doc.company})
|
||||||
if not dtl:
|
|
||||||
dtl = webnotes.conn.sql("""select * from `tabPOS Setting`
|
|
||||||
where ifnull(user,'') = '' and company = %s""", self.doc.company, as_dict=1)
|
|
||||||
self._pos_settings = dtl
|
|
||||||
|
|
||||||
return self._pos_settings
|
return self._pos_settings
|
||||||
|
|
||||||
def apply_pos_settings(self, args, ret=None):
|
|
||||||
if not ret: ret = {}
|
|
||||||
|
|
||||||
pos = self.pos_settings[0]
|
|
||||||
|
|
||||||
item = webnotes.conn.sql("""select default_income_account, default_sales_cost_center,
|
|
||||||
default_warehouse, purchase_account from tabItem where name = %s""",
|
|
||||||
args.get('item_code'), as_dict=1)
|
|
||||||
|
|
||||||
if item:
|
|
||||||
item = item[0]
|
|
||||||
|
|
||||||
ret.update({
|
|
||||||
"income_account": item.get("default_income_account") \
|
|
||||||
or pos.get("income_account") or args.get("income_account"),
|
|
||||||
"cost_center": item.get("default_sales_cost_center") \
|
|
||||||
or pos.get("cost_center") or args.get("cost_center"),
|
|
||||||
"warehouse": item.get("default_warehouse") \
|
|
||||||
or pos.get("warehouse") or args.get("warehouse"),
|
|
||||||
"expense_account": item.get("purchase_account") \
|
|
||||||
or pos.get("expense_account") or args.get("expense_account")
|
|
||||||
})
|
|
||||||
|
|
||||||
if ret.get("warehouse"):
|
|
||||||
ret["actual_qty"] = flt(webnotes.conn.get_value("Bin",
|
|
||||||
{"item_code": args.get("item_code"), "warehouse": args.get("warehouse")},
|
|
||||||
"actual_qty"))
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def get_barcode_details(self, barcode):
|
def get_barcode_details(self, barcode):
|
||||||
return get_obj('Sales Common').get_barcode_details(barcode)
|
return get_obj('Sales Common').get_barcode_details(barcode)
|
||||||
|
|
||||||
@ -375,14 +293,6 @@ class DocType(SellingController):
|
|||||||
return get_obj('Sales Common').get_tc_details(self)
|
return get_obj('Sales Common').get_tc_details(self)
|
||||||
|
|
||||||
|
|
||||||
def load_default_taxes(self):
|
|
||||||
self.doclist = get_obj('Sales Common').load_default_taxes(self)
|
|
||||||
|
|
||||||
|
|
||||||
def get_other_charges(self):
|
|
||||||
self.doclist = get_obj('Sales Common').get_other_charges(self)
|
|
||||||
|
|
||||||
|
|
||||||
def get_advances(self):
|
def get_advances(self):
|
||||||
super(DocType, self).get_advances(self.doc.debit_to,
|
super(DocType, self).get_advances(self.doc.debit_to,
|
||||||
"Sales Invoice Advance", "advance_adjustment_details", "credit")
|
"Sales Invoice Advance", "advance_adjustment_details", "credit")
|
||||||
@ -611,7 +521,9 @@ class DocType(SellingController):
|
|||||||
else:
|
else:
|
||||||
self.doclist = self.doc.clear_table(self.doclist, 'packing_details')
|
self.doclist = self.doc.clear_table(self.doclist, 'packing_details')
|
||||||
webnotes.conn.set(self.doc,'paid_amount',0)
|
webnotes.conn.set(self.doc,'paid_amount',0)
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
# move to calculations
|
||||||
webnotes.conn.set(self.doc, 'outstanding_amount',
|
webnotes.conn.set(self.doc, 'outstanding_amount',
|
||||||
flt(self.doc.grand_total) - flt(self.doc.total_advance) -
|
flt(self.doc.grand_total) - flt(self.doc.total_advance) -
|
||||||
flt(self.doc.paid_amount) - flt(self.doc.write_off_amount))
|
flt(self.doc.paid_amount) - flt(self.doc.write_off_amount))
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-05-06 12:03:41",
|
"creation": "2013-05-21 16:16:41",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-05-09 17:34:14",
|
"modified": "2013-05-21 18:25:07",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -224,11 +224,12 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "entries",
|
"fieldname": "entries",
|
||||||
"fieldtype": "Table",
|
"fieldtype": "Table",
|
||||||
"label": "Entries",
|
"label": "Sales Invoice Items",
|
||||||
"oldfieldname": "entries",
|
"oldfieldname": "entries",
|
||||||
"oldfieldtype": "Table",
|
"oldfieldtype": "Table",
|
||||||
"options": "Sales Invoice Item",
|
"options": "Sales Invoice Item",
|
||||||
"read_only": 0
|
"read_only": 0,
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@ -460,6 +461,15 @@
|
|||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"doctype": "DocField",
|
||||||
|
"fieldname": "other_charges_total_export",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"label": "Total Taxes and Charges (Export)",
|
||||||
|
"options": "currency",
|
||||||
|
"print_hide": 1,
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "other_charges_calculation",
|
"fieldname": "other_charges_calculation",
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-04-10 08:35:44",
|
"creation": "2013-04-19 13:30:26",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-04-17 14:05:20",
|
"modified": "2013-05-21 16:43:21",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -107,7 +107,7 @@
|
|||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"options": "currency",
|
"options": "currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 0,
|
"read_only": 1,
|
||||||
"reqd": 0
|
"reqd": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -163,7 +163,7 @@
|
|||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 0,
|
"read_only": 1,
|
||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 0
|
"search_index": 0
|
||||||
},
|
},
|
||||||
|
@ -84,20 +84,8 @@ erpnext.buying.BuyingController = wn.ui.form.Controller.extend({
|
|||||||
item_code: function(doc, cdt, cdn) {
|
item_code: function(doc, cdt, cdn) {
|
||||||
var me = this;
|
var me = this;
|
||||||
var item = wn.model.get_doc(cdt, cdn);
|
var item = wn.model.get_doc(cdt, cdn);
|
||||||
|
|
||||||
// validate company
|
|
||||||
if(item.item_code) {
|
if(item.item_code) {
|
||||||
var fetch = true;
|
if(!this.validate_company_and_party()) {
|
||||||
$.each(["company", "supplier"], function(i, fieldname) {
|
|
||||||
if(!me.frm.doc[fieldname]) {
|
|
||||||
fetch = false;
|
|
||||||
msgprint(wn._("Please specify") + ": " +
|
|
||||||
wn.meta.get_label(me.frm.doc.doctype, fieldname, me.frm.doc.name) +
|
|
||||||
". " + wn._("It is needed to fetch Item Details."));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if(!fetch) {
|
|
||||||
item.item_code = null;
|
item.item_code = null;
|
||||||
refresh_field("item_code", item.name, item.parentfield);
|
refresh_field("item_code", item.name, item.parentfield);
|
||||||
} else {
|
} else {
|
||||||
@ -128,6 +116,19 @@ erpnext.buying.BuyingController = wn.ui.form.Controller.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
validate_company_and_party: function() {
|
||||||
|
var valid = true;
|
||||||
|
$.each(["company", "supplier"], function(i, fieldname) {
|
||||||
|
if(!me.frm.doc[fieldname]) {
|
||||||
|
valid = false;
|
||||||
|
msgprint(wn._("Please specify") + ": " +
|
||||||
|
wn.meta.get_label(me.frm.doc.doctype, fieldname, me.frm.doc.name) +
|
||||||
|
". " + wn._("It is needed to fetch Item Details."));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return valid;
|
||||||
|
},
|
||||||
|
|
||||||
update_item_details: function(doc, dt, dn, callback) {
|
update_item_details: function(doc, dt, dn, callback) {
|
||||||
if(!this.frm.doc.__islocal) return;
|
if(!this.frm.doc.__islocal) return;
|
||||||
|
|
||||||
|
@ -59,23 +59,12 @@ def get_item_details(args):
|
|||||||
out.schedule_date = out.lead_time_date = add_days(args.transaction_date,
|
out.schedule_date = out.lead_time_date = add_days(args.transaction_date,
|
||||||
item.lead_time_days)
|
item.lead_time_days)
|
||||||
|
|
||||||
# set zero
|
meta = webnotes.get_doctype(args.doctype)
|
||||||
out.purchase_ref_rate = out.discount_rate = out.purchase_rate = \
|
|
||||||
out.import_ref_rate = out.import_rate = 0.0
|
|
||||||
|
|
||||||
if args.doctype in ["Purchase Order", "Purchase Invoice", "Purchase Receipt",
|
if meta.get_field("currency"):
|
||||||
"Supplier Quotation"]:
|
out.purchase_ref_rate = out.discount_rate = out.purchase_rate = \
|
||||||
# try fetching from price list
|
out.import_ref_rate = out.import_rate = 0.0
|
||||||
if args.price_list_name and args.price_list_currency:
|
out.update(_get_price_list_rate(args, item_bean, meta))
|
||||||
rates_as_per_price_list = get_rates_as_per_price_list(args, item_bean.doclist)
|
|
||||||
if rates_as_per_price_list:
|
|
||||||
out.update(rates_as_per_price_list)
|
|
||||||
|
|
||||||
# if not found, fetch from last purchase transaction
|
|
||||||
if not out.purchase_rate:
|
|
||||||
last_purchase = get_last_purchase_details(item.name, args.docname, args.conversion_rate)
|
|
||||||
if last_purchase:
|
|
||||||
out.update(last_purchase)
|
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
@ -100,34 +89,38 @@ def _get_basic_details(args, item_bean):
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
def _get_price_list_rate(args, item_bean, meta=None):
|
||||||
|
from utilities.transaction_base import validate_currency
|
||||||
|
item = item_bean.doc
|
||||||
|
out = webnotes._dict()
|
||||||
|
|
||||||
|
# try fetching from price list
|
||||||
|
if args.price_list_name and args.price_list_currency:
|
||||||
|
price_list_rate = item_bean.doclist.get({
|
||||||
|
"parentfield": "ref_rate_details",
|
||||||
|
"price_list_name": args.price_list_name,
|
||||||
|
"ref_currency": args.price_list_currency,
|
||||||
|
"buying": 1})
|
||||||
|
if price_list_rate:
|
||||||
|
out.purchase_ref_rate = flt(price_list_rate[0].ref_rate) * flt(args.plc_conversion_rate)
|
||||||
|
|
||||||
|
# if not found, fetch from last purchase transaction
|
||||||
|
if not out.purchase_ref_rate:
|
||||||
|
last_purchase = get_last_purchase_details(item.name, args.docname, args.conversion_rate)
|
||||||
|
if last_purchase:
|
||||||
|
out.update(last_purchase)
|
||||||
|
|
||||||
|
if out.purchase_ref_rate or out.purchase_rate or out.rate:
|
||||||
|
validate_currency(args, item, meta)
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
def _get_supplier_part_no(args, item_bean):
|
def _get_supplier_part_no(args, item_bean):
|
||||||
item_supplier = item_bean.doclist.get({"parentfield": "item_supplier_details",
|
item_supplier = item_bean.doclist.get({"parentfield": "item_supplier_details",
|
||||||
"supplier": args.supplier})
|
"supplier": args.supplier})
|
||||||
|
|
||||||
return item_supplier and item_supplier[0].supplier_part_no or None
|
return item_supplier and item_supplier[0].supplier_part_no or None
|
||||||
|
|
||||||
def get_rates_as_per_price_list(args, item_doclist=None):
|
|
||||||
if not item_doclist:
|
|
||||||
item_doclist = webnotes.bean("Item", args.item_code).doclist
|
|
||||||
|
|
||||||
result = item_doclist.get({"parentfield": "ref_rate_details",
|
|
||||||
"price_list_name": args.price_list_name, "ref_currency": args.price_list_currency,
|
|
||||||
"buying": 1})
|
|
||||||
|
|
||||||
if result:
|
|
||||||
purchase_ref_rate = flt(result[0].ref_rate) * flt(args.plc_conversion_rate)
|
|
||||||
conversion_rate = flt(args.conversion_rate) or 1.0
|
|
||||||
return webnotes._dict({
|
|
||||||
"purchase_ref_rate": purchase_ref_rate,
|
|
||||||
"purchase_rate": purchase_ref_rate,
|
|
||||||
"rate": purchase_ref_rate,
|
|
||||||
"discount_rate": 0,
|
|
||||||
"import_ref_rate": purchase_ref_rate / conversion_rate,
|
|
||||||
"import_rate": purchase_ref_rate / conversion_rate
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
return webnotes._dict()
|
|
||||||
|
|
||||||
def _validate_item_details(args, item):
|
def _validate_item_details(args, item):
|
||||||
from utilities.transaction_base import validate_item_fetch
|
from utilities.transaction_base import validate_item_fetch
|
||||||
validate_item_fetch(args, item)
|
validate_item_fetch(args, item)
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import cint, flt
|
from webnotes.utils import cint, flt, comma_or
|
||||||
from setup.utils import get_company_currency
|
from setup.utils import get_company_currency
|
||||||
from webnotes import msgprint, _
|
from webnotes import msgprint, _
|
||||||
import json
|
import json
|
||||||
@ -24,9 +24,73 @@ import json
|
|||||||
from controllers.stock_controller import StockController
|
from controllers.stock_controller import StockController
|
||||||
|
|
||||||
class SellingController(StockController):
|
class SellingController(StockController):
|
||||||
|
def onload_post_render(self):
|
||||||
|
self.set_price_list_currency()
|
||||||
|
|
||||||
|
# contact, address, item details and pos details (if applicable)
|
||||||
|
self.set_missing_values()
|
||||||
|
|
||||||
|
if self.meta.get_field("other_charges"):
|
||||||
|
self.set_taxes()
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
super(SellingController, self).validate()
|
super(SellingController, self).validate()
|
||||||
|
# self.calculate_taxes_and_totals()
|
||||||
self.set_total_in_words()
|
self.set_total_in_words()
|
||||||
|
self.set_missing_values(for_validate=True)
|
||||||
|
|
||||||
|
def set_price_list_currency(self):
|
||||||
|
if self.doc.price_list_name and not self.doc.price_list_currency:
|
||||||
|
# TODO - change this, since price list now has only one currency allowed
|
||||||
|
from setup.utils import get_price_list_currency
|
||||||
|
self.doc.fields.update(get_price_list_currency(
|
||||||
|
{"price_list_name": self.doc.price_list_name, "use_for": "selling"}))
|
||||||
|
|
||||||
|
def set_missing_values(self, for_validate=False):
|
||||||
|
# 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
|
||||||
|
|
||||||
|
# set missing item values
|
||||||
|
from selling.utils import get_item_details
|
||||||
|
for item in self.doclist.get({"parentfield": "entries"}):
|
||||||
|
if item.fields.get("item_code"):
|
||||||
|
ret = get_item_details(item.fields)
|
||||||
|
for fieldname, value in ret.items():
|
||||||
|
if self.meta.get_field(fieldname, parentfield="entries") and \
|
||||||
|
not item.fields.get(fieldname):
|
||||||
|
item.fields[fieldname] = value
|
||||||
|
|
||||||
|
def set_taxes(self):
|
||||||
|
if not self.doclist.get({"parentfield": "other_charges"}):
|
||||||
|
if not self.doc.charge:
|
||||||
|
# get the default tax master
|
||||||
|
self.doc.charge = webnotes.conn.get_value("Sales Taxes and Charges Master",
|
||||||
|
{"is_default": 1})
|
||||||
|
|
||||||
|
if self.doc.charge:
|
||||||
|
from webnotes.model import default_fields
|
||||||
|
tax_master = webnotes.bean("Sales Taxes and Charges Master", self.doc.charge)
|
||||||
|
for i, tax in enumerate(tax_master.doclist.get({"parentfield": "other_charges"})):
|
||||||
|
for fieldname in default_fields:
|
||||||
|
tax.fields[fieldname] = None
|
||||||
|
|
||||||
|
tax.fields.update({
|
||||||
|
"doctype": "Sales Taxes and Charges",
|
||||||
|
"parentfield": "other_charges",
|
||||||
|
"idx": i+1
|
||||||
|
})
|
||||||
|
|
||||||
|
self.doclist.append(tax)
|
||||||
|
|
||||||
|
def get_other_charges(self):
|
||||||
|
self.doclist = self.doc.clear_table(self.doclist, "other_charges")
|
||||||
|
self.set_taxes()
|
||||||
|
|
||||||
|
def set_customer_defaults(self):
|
||||||
|
self.get_default_customer_address()
|
||||||
|
|
||||||
def set_total_in_words(self):
|
def set_total_in_words(self):
|
||||||
from webnotes.utils import money_in_words
|
from webnotes.utils import money_in_words
|
||||||
@ -81,25 +145,19 @@ class SellingController(StockController):
|
|||||||
|
|
||||||
self.calculate_item_values()
|
self.calculate_item_values()
|
||||||
self.initialize_taxes()
|
self.initialize_taxes()
|
||||||
|
self.determine_exclusive_rate()
|
||||||
self.determin_exclusive_rate()
|
|
||||||
|
|
||||||
# TODO
|
|
||||||
# code: save net_total_export on client side
|
|
||||||
# print format: show net_total_export instead of net_total
|
|
||||||
|
|
||||||
self.calculate_net_total()
|
self.calculate_net_total()
|
||||||
self.calculate_taxes()
|
self.calculate_taxes()
|
||||||
self.calculate_totals()
|
self.calculate_totals()
|
||||||
|
self.calculate_commission()
|
||||||
|
self.calculate_contribution()
|
||||||
# self.calculate_outstanding_amount()
|
# self.calculate_outstanding_amount()
|
||||||
|
|
||||||
# TODO
|
|
||||||
# allocated amount of sales person
|
|
||||||
# total commission
|
|
||||||
|
|
||||||
self._cleanup()
|
self._cleanup()
|
||||||
|
|
||||||
def determin_exclusive_rate(self):
|
# TODO
|
||||||
|
# print format: show net_total_export instead of net_total
|
||||||
|
|
||||||
|
def determine_exclusive_rate(self):
|
||||||
if not any((cint(tax.included_in_print_rate) for tax in self.tax_doclist)):
|
if not any((cint(tax.included_in_print_rate) for tax in self.tax_doclist)):
|
||||||
# no inclusive tax
|
# no inclusive tax
|
||||||
return
|
return
|
||||||
@ -108,15 +166,10 @@ class SellingController(StockController):
|
|||||||
item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
|
item_tax_map = self._load_item_tax_rate(item.item_tax_rate)
|
||||||
cumulated_tax_fraction = 0
|
cumulated_tax_fraction = 0
|
||||||
for i, tax in enumerate(self.tax_doclist):
|
for i, tax in enumerate(self.tax_doclist):
|
||||||
if cint(tax.included_in_print_rate):
|
tax.tax_fraction_for_current_item = self.get_current_tax_fraction(tax, item_tax_map)
|
||||||
tax.tax_fraction_for_current_item = \
|
|
||||||
self.get_current_tax_fraction(tax, item_tax_map)
|
|
||||||
else:
|
|
||||||
tax.tax_fraction_for_current_item = 0
|
|
||||||
|
|
||||||
if i==0:
|
if i==0:
|
||||||
tax.grand_total_fraction_for_current_item = 1 + \
|
tax.grand_total_fraction_for_current_item = 1 + tax.tax_fraction_for_current_item
|
||||||
tax.tax_fraction_for_current_item
|
|
||||||
else:
|
else:
|
||||||
tax.grand_total_fraction_for_current_item = \
|
tax.grand_total_fraction_for_current_item = \
|
||||||
self.tax_doclist[i-1].grand_total_fraction_for_current_item \
|
self.tax_doclist[i-1].grand_total_fraction_for_current_item \
|
||||||
@ -130,8 +183,12 @@ class SellingController(StockController):
|
|||||||
|
|
||||||
item.amount = flt(item.basic_rate * item.qty, self.precision("amount", item))
|
item.amount = flt(item.basic_rate * item.qty, self.precision("amount", item))
|
||||||
|
|
||||||
item.base_ref_rate = flt(item.basic_rate / (1 - (item.adj_rate / 100.0)),
|
if item.adj_rate == 100:
|
||||||
self.precision("base_ref_rate", item))
|
item.base_ref_rate = item.basic_rate
|
||||||
|
item.basic_rate = 0.0
|
||||||
|
else:
|
||||||
|
item.base_ref_rate = flt(item.basic_rate / (1 - (item.adj_rate / 100.0)),
|
||||||
|
self.precision("base_ref_rate", item))
|
||||||
|
|
||||||
def get_current_tax_fraction(self, tax, item_tax_map):
|
def get_current_tax_fraction(self, tax, item_tax_map):
|
||||||
"""
|
"""
|
||||||
@ -188,24 +245,23 @@ class SellingController(StockController):
|
|||||||
def initialize_taxes(self):
|
def initialize_taxes(self):
|
||||||
for tax in self.tax_doclist:
|
for tax in self.tax_doclist:
|
||||||
tax.tax_amount = tax.total = 0.0
|
tax.tax_amount = tax.total = 0.0
|
||||||
|
tax.item_wise_tax_detail = {}
|
||||||
|
|
||||||
# temporary fields
|
# temporary fields
|
||||||
tax.tax_amount_for_current_item = tax.grand_total_for_current_item = 0.0
|
tax.tax_amount_for_current_item = tax.grand_total_for_current_item = 0.0
|
||||||
tax.item_wise_tax_detail = {}
|
|
||||||
self.validate_on_previous_row(tax)
|
self.validate_on_previous_row(tax)
|
||||||
self.validate_inclusive_tax(tax)
|
self.validate_inclusive_tax(tax)
|
||||||
self.round_floats_in(tax)
|
self.round_floats_in(tax)
|
||||||
|
|
||||||
def calculate_net_total(self):
|
def calculate_net_total(self):
|
||||||
self.doc.net_total = 0
|
self.doc.net_total = self.doc.net_total_export = 0.0
|
||||||
self.doc.net_total_export = 0
|
|
||||||
|
|
||||||
for item in self.item_doclist:
|
for item in self.item_doclist:
|
||||||
self.doc.net_total += item.amount
|
self.doc.net_total += item.amount
|
||||||
self.doc.net_total_export += item.export_amount
|
self.doc.net_total_export += item.export_amount
|
||||||
|
|
||||||
self.doc.net_total = flt(self.doc.net_total, self.precision("net_total"))
|
self.round_floats_in(self.doc, ["net_total", "net_total_export"])
|
||||||
self.doc.net_total_export = flt(self.doc.net_total_export,
|
|
||||||
self.precision("net_total_export"))
|
|
||||||
|
|
||||||
def calculate_taxes(self):
|
def calculate_taxes(self):
|
||||||
for item in self.item_doclist:
|
for item in self.item_doclist:
|
||||||
@ -218,8 +274,8 @@ class SellingController(StockController):
|
|||||||
# case when net total is 0 but there is an actual type charge
|
# case when net total is 0 but there is an actual type charge
|
||||||
# in this case add the actual amount to tax.tax_amount
|
# in this case add the actual amount to tax.tax_amount
|
||||||
# and tax.grand_total_for_current_item for the first such iteration
|
# and tax.grand_total_for_current_item for the first such iteration
|
||||||
if not (current_tax_amount or self.doc.net_total or tax.tax_amount) and \
|
if tax.charge_type=="Actual" and \
|
||||||
tax.charge_type=="Actual":
|
not (current_tax_amount or self.doc.net_total or tax.tax_amount):
|
||||||
zero_net_total_adjustment = flt(tax.rate, self.precision("tax_amount", tax))
|
zero_net_total_adjustment = flt(tax.rate, self.precision("tax_amount", tax))
|
||||||
current_tax_amount += zero_net_total_adjustment
|
current_tax_amount += zero_net_total_adjustment
|
||||||
|
|
||||||
@ -228,7 +284,7 @@ class SellingController(StockController):
|
|||||||
tax.tax_amount_for_current_item = current_tax_amount
|
tax.tax_amount_for_current_item = current_tax_amount
|
||||||
|
|
||||||
# accumulate tax amount into tax.tax_amount
|
# accumulate tax amount into tax.tax_amount
|
||||||
tax.tax_amount += tax.tax_amount_for_current_item
|
tax.tax_amount += current_tax_amount
|
||||||
|
|
||||||
# Calculate tax.total viz. grand total till that step
|
# Calculate tax.total viz. grand total till that step
|
||||||
# note: grand_total_for_current_item contains the contribution of
|
# note: grand_total_for_current_item contains the contribution of
|
||||||
@ -245,8 +301,7 @@ class SellingController(StockController):
|
|||||||
# in tax.total, accumulate grand total of each item
|
# in tax.total, accumulate grand total of each item
|
||||||
tax.total += tax.grand_total_for_current_item
|
tax.total += tax.grand_total_for_current_item
|
||||||
|
|
||||||
# store tax_breakup for each item
|
# store tax breakup for each item
|
||||||
# DOUBT: should valuation type amount also be stored?
|
|
||||||
tax.item_wise_tax_detail[item.item_code] = current_tax_amount
|
tax.item_wise_tax_detail[item.item_code] = current_tax_amount
|
||||||
|
|
||||||
def calculate_totals(self):
|
def calculate_totals(self):
|
||||||
@ -254,12 +309,43 @@ class SellingController(StockController):
|
|||||||
self.tax_doclist[-1].total or self.doc.net_total, self.precision("grand_total"))
|
self.tax_doclist[-1].total or self.doc.net_total, self.precision("grand_total"))
|
||||||
self.doc.grand_total_export = flt(self.doc.grand_total / self.doc.conversion_rate,
|
self.doc.grand_total_export = flt(self.doc.grand_total / self.doc.conversion_rate,
|
||||||
self.precision("grand_total_export"))
|
self.precision("grand_total_export"))
|
||||||
|
|
||||||
|
self.doc.other_charges_total = flt(self.doc.grand_total - self.doc.net_total,
|
||||||
|
self.precision("other_charges_total"))
|
||||||
|
self.doc.other_charges_total_export = flt(self.doc.grand_total_export - self.doc.net_total_export,
|
||||||
|
self.precision("other_charges_total_export"))
|
||||||
|
|
||||||
self.doc.rounded_total = round(self.doc.grand_total)
|
self.doc.rounded_total = round(self.doc.grand_total)
|
||||||
self.doc.rounded_total_export = round(self.doc.grand_total_export)
|
self.doc.rounded_total_export = round(self.doc.grand_total_export)
|
||||||
|
|
||||||
|
def calculate_commission(self):
|
||||||
|
if self.doc.commission_rate > 100:
|
||||||
|
msgprint(_(self.meta.get_label("commission_rate")) + " " +
|
||||||
|
_("cannot be greater than 100"), raise_exception=True)
|
||||||
|
|
||||||
|
self.doc.total_commission = flt(self.doc.net_total * self.doc.commission_rate / 100.0,
|
||||||
|
self.precision("total_commission"))
|
||||||
|
|
||||||
|
def calculate_contribution(self):
|
||||||
|
total = 0.0
|
||||||
|
sales_team = self.doclist.get({"parentfield": "sales_team"})
|
||||||
|
for sales_person in sales_team:
|
||||||
|
self.round_floats_in(sales_person)
|
||||||
|
|
||||||
|
sales_person.allocated_amount = flt(
|
||||||
|
self.doc.net_total * sales_person.allocated_percentage / 100.0,
|
||||||
|
self.precision("allocated_amount", sales_person))
|
||||||
|
|
||||||
|
total += sales_person.allocated_percentage
|
||||||
|
|
||||||
|
if sales_team and total != 100.0:
|
||||||
|
msgprint(_("Total") + " " +
|
||||||
|
_(self.meta.get_label("allocated_percentage", parentfield="sales_team")) +
|
||||||
|
" " + _("should be 100%"), raise_exception=True)
|
||||||
|
|
||||||
def get_current_tax_amount(self, item, tax, item_tax_map):
|
def get_current_tax_amount(self, item, tax, item_tax_map):
|
||||||
tax_rate = self._get_tax_rate(tax, item_tax_map)
|
tax_rate = self._get_tax_rate(tax, item_tax_map)
|
||||||
|
current_tax_amount = 0.0
|
||||||
|
|
||||||
if tax.charge_type == "Actual":
|
if tax.charge_type == "Actual":
|
||||||
# distribute the tax amount proportionally to each item row
|
# distribute the tax amount proportionally to each item row
|
||||||
@ -288,20 +374,18 @@ class SellingController(StockController):
|
|||||||
msgprint((_("Row") + " # %(idx)s [%(taxes_doctype)s]: " + \
|
msgprint((_("Row") + " # %(idx)s [%(taxes_doctype)s]: " + \
|
||||||
_("Please specify a valid") + " %(row_id_label)s") % {
|
_("Please specify a valid") + " %(row_id_label)s") % {
|
||||||
"idx": tax.idx,
|
"idx": tax.idx,
|
||||||
"taxes_doctype": tax.parenttype,
|
"taxes_doctype": tax.doctype,
|
||||||
"row_id_label": self.meta.get_label("row_id",
|
"row_id_label": self.meta.get_label("row_id",
|
||||||
parentfield="other_charges")
|
parentfield="other_charges")
|
||||||
}, raise_exception=True)
|
}, raise_exception=True)
|
||||||
|
|
||||||
def validate_inclusive_tax(self, tax):
|
def validate_inclusive_tax(self, tax):
|
||||||
def _on_previous_row_error(tax, row_range):
|
def _on_previous_row_error(row_range):
|
||||||
msgprint((_("Row")
|
msgprint((_("Row") + " # %(idx)s [%(doctype)s]: " +
|
||||||
+ " # %(idx)s [%(taxes_doctype)s] [%(charge_type_label)s = \"%(charge_type)s\"]: "
|
_("to be included in Item's rate, it is required that: ") +
|
||||||
+ _("If:") + ' "%(inclusive_label)s" = ' + _("checked") + ", "
|
" [" + _("Row") + " # %(row_range)s] " + _("also be included in Item's rate")) % {
|
||||||
+ _("then it is required that:") + " [" + _("Row") + " # %(row_range)s] "
|
|
||||||
+ '"%(inclusive_label)s" = ' + _("checked")) % {
|
|
||||||
"idx": tax.idx,
|
"idx": tax.idx,
|
||||||
"taxes_doctype": tax.doctype,
|
"doctype": tax.doctype,
|
||||||
"inclusive_label": self.meta.get_label("included_in_print_rate",
|
"inclusive_label": self.meta.get_label("included_in_print_rate",
|
||||||
parentfield="other_charges"),
|
parentfield="other_charges"),
|
||||||
"charge_type_label": self.meta.get_label("charge_type",
|
"charge_type_label": self.meta.get_label("charge_type",
|
||||||
@ -312,12 +396,12 @@ class SellingController(StockController):
|
|||||||
|
|
||||||
if cint(tax.included_in_print_rate):
|
if cint(tax.included_in_print_rate):
|
||||||
if tax.charge_type == "Actual":
|
if tax.charge_type == "Actual":
|
||||||
# inclusive cannot be of type Actual
|
# inclusive tax cannot be of type Actual
|
||||||
msgprint((_("Row")
|
msgprint((_("Row")
|
||||||
+ " # %(idx)s [%(taxes_doctype)s]: %(charge_type_label)s = \"%(charge_type)s\" "
|
+ " # %(idx)s [%(doctype)s]: %(charge_type_label)s = \"%(charge_type)s\" "
|
||||||
+ "cannot be included in Item's rate") % {
|
+ "cannot be included in Item's rate") % {
|
||||||
"idx": tax.idx,
|
"idx": tax.idx,
|
||||||
"taxes_doctype": tax.doctype,
|
"doctype": tax.doctype,
|
||||||
"charge_type_label": self.meta.get_label("charge_type",
|
"charge_type_label": self.meta.get_label("charge_type",
|
||||||
parentfield="other_charges"),
|
parentfield="other_charges"),
|
||||||
"charge_type": tax.charge_type,
|
"charge_type": tax.charge_type,
|
||||||
@ -325,16 +409,14 @@ class SellingController(StockController):
|
|||||||
elif tax.charge_type == "On Previous Row Amount" and \
|
elif tax.charge_type == "On Previous Row Amount" and \
|
||||||
not cint(self.tax_doclist[tax.row_id - 1].included_in_print_rate):
|
not cint(self.tax_doclist[tax.row_id - 1].included_in_print_rate):
|
||||||
# referred row should also be inclusive
|
# referred row should also be inclusive
|
||||||
_on_previous_row_error(tax, tax.row_id)
|
_on_previous_row_error(tax.row_id)
|
||||||
elif tax.charge_type == "On Previous Row Total" and \
|
elif tax.charge_type == "On Previous Row Total" and \
|
||||||
not all([cint(t.included_in_print_rate) for t in self.tax_doclist[:tax.idx - 1]]):
|
not all([cint(t.included_in_print_rate) for t in self.tax_doclist[:tax.row_id - 1]]):
|
||||||
# all rows about this tax should be inclusive
|
# all rows about the reffered tax should be inclusive
|
||||||
_on_previous_row_error(tax, "1 - %d" % (tax.idx - 1,))
|
_on_previous_row_error("1 - %d" % (tax.row_id,))
|
||||||
|
|
||||||
def _load_item_tax_rate(self, item_tax_rate):
|
def _load_item_tax_rate(self, item_tax_rate):
|
||||||
if not item_tax_rate:
|
return json.loads(item_tax_rate) if item_tax_rate else {}
|
||||||
return {}
|
|
||||||
return json.loads(item_tax_rate)
|
|
||||||
|
|
||||||
def _get_tax_rate(self, tax, item_tax_map):
|
def _get_tax_rate(self, tax, item_tax_map):
|
||||||
if item_tax_map.has_key(tax.account_head):
|
if item_tax_map.has_key(tax.account_head):
|
||||||
@ -344,10 +426,9 @@ class SellingController(StockController):
|
|||||||
|
|
||||||
def _cleanup(self):
|
def _cleanup(self):
|
||||||
for tax in self.tax_doclist:
|
for tax in self.tax_doclist:
|
||||||
del tax.fields["grand_total_for_current_item"]
|
for fieldname in ("grand_total_for_current_item",
|
||||||
del tax.fields["tax_amount_for_current_item"]
|
"tax_amount_for_current_item",
|
||||||
|
"tax_fraction_for_current_item",
|
||||||
for fieldname in ("tax_fraction_for_current_item",
|
|
||||||
"grand_total_fraction_for_current_item"):
|
"grand_total_fraction_for_current_item"):
|
||||||
if fieldname in tax.fields:
|
if fieldname in tax.fields:
|
||||||
del tax.fields[fieldname]
|
del tax.fields[fieldname]
|
||||||
|
@ -1,10 +1,29 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
|
from webnotes.utils import cint
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
for module, doctype in (("Accounts", "Sales Invoice"), ("Selling", "Sales Order"), ("Selling", "Quotation"),
|
for module, doctype in (("Accounts", "Sales Invoice"), ("Selling", "Sales Order"), ("Selling", "Quotation"),
|
||||||
("Stock", "Delivery Note")):
|
("Stock", "Delivery Note")):
|
||||||
webnotes.reload_doc(module, "DocType", doctype)
|
webnotes.reload_doc(module, "DocType", doctype)
|
||||||
webnotes.conn.sql("""update `tab%s`
|
webnotes.conn.sql("""update `tab%s`
|
||||||
set net_total_export = round(net_total / if(conversion_rate=0, 1, ifnull(conversion_rate, 1)), 2)""" %
|
set net_total_export = round(net_total / if(conversion_rate=0, 1, ifnull(conversion_rate, 1)), 2),
|
||||||
(doctype,))
|
other_charges_total_export = round(grand_total_export - net_total_export, 2)""" %
|
||||||
|
(doctype,))
|
||||||
|
|
||||||
|
for module, doctype in (("Accounts", "Sales Invoice Item"), ("Selling", "Sales Order Item"), ("Selling", "Quotation Item"),
|
||||||
|
("Stock", "Delivery Note Item")):
|
||||||
|
if cint(webnotes.conn.get_value("DocField", {"parent": doctype, "fieldname": "ref_rate"}, "read_only")) == 0 and \
|
||||||
|
not webnotes.conn.sql("""select name from `tabProperty Setter` where doc_type=%s and doctype_or_field='DocField'
|
||||||
|
and field_name='ref_rate' and property='read_only'""", doctype):
|
||||||
|
webnotes.bean({
|
||||||
|
"doctype": "Property Setter",
|
||||||
|
"doc_type": doctype,
|
||||||
|
"doctype_or_field": "DocField",
|
||||||
|
"field_name": "ref_rate",
|
||||||
|
"property": "read_only",
|
||||||
|
"property_type": "Check",
|
||||||
|
"value": "0"
|
||||||
|
}).insert()
|
||||||
|
|
||||||
|
webnotes.reload_doc(module, "DocType", doctype)
|
@ -95,17 +95,6 @@ class DocType(SellingController):
|
|||||||
def get_rate(self,arg):
|
def get_rate(self,arg):
|
||||||
return get_obj('Sales Common').get_rate(arg)
|
return get_obj('Sales Common').get_rate(arg)
|
||||||
|
|
||||||
# Load Default Charges
|
|
||||||
# ----------------------------------------------------------
|
|
||||||
def load_default_taxes(self):
|
|
||||||
self.doclist = get_obj('Sales Common').load_default_taxes(self)
|
|
||||||
|
|
||||||
# Pull details from other charges master (Get Sales Taxes and Charges Master)
|
|
||||||
# ----------------------------------------------------------
|
|
||||||
def get_other_charges(self):
|
|
||||||
self.doclist = get_obj('Sales Common').get_other_charges(self)
|
|
||||||
|
|
||||||
|
|
||||||
# GET TERMS AND CONDITIONS
|
# GET TERMS AND CONDITIONS
|
||||||
# ====================================================================================
|
# ====================================================================================
|
||||||
def get_tc_details(self):
|
def get_tc_details(self):
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-05-06 12:03:40",
|
"creation": "2013-05-21 16:16:40",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-05-06 13:07:37",
|
"modified": "2013-05-21 18:29:59",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -214,6 +214,7 @@
|
|||||||
"oldfieldtype": "Table",
|
"oldfieldtype": "Table",
|
||||||
"options": "Quotation Item",
|
"options": "Quotation Item",
|
||||||
"read_only": 0,
|
"read_only": 0,
|
||||||
|
"reqd": 1,
|
||||||
"width": "40px"
|
"width": "40px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -431,13 +432,22 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "other_charges_total",
|
"fieldname": "other_charges_total",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"label": "Taxes and Charges Total*",
|
"label": "Taxes and Charges Total",
|
||||||
"oldfieldname": "other_charges_total",
|
"oldfieldname": "other_charges_total",
|
||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"doctype": "DocField",
|
||||||
|
"fieldname": "other_charges_total_export",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"label": "Taxes and Charges Total (Export)",
|
||||||
|
"options": "currency",
|
||||||
|
"print_hide": 1,
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "other_charges_calculation",
|
"fieldname": "other_charges_calculation",
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-02-22 01:27:52",
|
"creation": "2013-04-19 13:30:50",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-03-07 07:03:29",
|
"modified": "2013-05-21 16:45:44",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -115,6 +115,7 @@
|
|||||||
"options": "currency",
|
"options": "currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"print_width": "100px",
|
"print_width": "100px",
|
||||||
|
"read_only": 1,
|
||||||
"reqd": 0,
|
"reqd": 0,
|
||||||
"width": "100px"
|
"width": "100px"
|
||||||
},
|
},
|
||||||
@ -188,6 +189,7 @@
|
|||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"print_width": "100px",
|
"print_width": "100px",
|
||||||
|
"read_only": 1,
|
||||||
"reqd": 0,
|
"reqd": 0,
|
||||||
"search_index": 0,
|
"search_index": 0,
|
||||||
"width": "100px"
|
"width": "100px"
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -28,23 +28,6 @@ get_value = webnotes.conn.get_value
|
|||||||
|
|
||||||
from utilities.transaction_base import TransactionBase
|
from utilities.transaction_base import TransactionBase
|
||||||
|
|
||||||
|
|
||||||
@webnotes.whitelist()
|
|
||||||
def get_comp_base_currency(arg=None):
|
|
||||||
""" get default currency of company"""
|
|
||||||
res = webnotes.conn.sql("""select default_currency from `tabCompany`
|
|
||||||
where name = %s""", webnotes.form_dict.get('company'))
|
|
||||||
return res and res[0][0] or None
|
|
||||||
|
|
||||||
@webnotes.whitelist()
|
|
||||||
def get_price_list_currency(arg=None):
|
|
||||||
""" Get all currency in which price list is maintained"""
|
|
||||||
plc = webnotes.conn.sql("select distinct ref_currency from `tabItem Price` where price_list_name = %s", webnotes.form_dict['price_list'])
|
|
||||||
plc = [d[0] for d in plc]
|
|
||||||
base_currency = get_comp_base_currency(webnotes.form_dict['company'])
|
|
||||||
return plc, base_currency
|
|
||||||
|
|
||||||
|
|
||||||
class DocType(TransactionBase):
|
class DocType(TransactionBase):
|
||||||
def __init__(self,d,dl):
|
def __init__(self,d,dl):
|
||||||
self.doc, self.doclist = d,dl
|
self.doc, self.doclist = d,dl
|
||||||
@ -122,67 +105,67 @@ class DocType(TransactionBase):
|
|||||||
|
|
||||||
# Get Item Details
|
# Get Item Details
|
||||||
# ===============================================================
|
# ===============================================================
|
||||||
def get_item_details(self, args, obj):
|
# def get_item_details(self, args, obj):
|
||||||
import json
|
# import json
|
||||||
if not obj.doc.price_list_name:
|
# if not obj.doc.price_list_name:
|
||||||
msgprint("Please Select Price List before selecting Items", raise_exception=True)
|
# msgprint("Please Select Price List before selecting Items", raise_exception=True)
|
||||||
item = webnotes.conn.sql("""select description, item_name, brand, item_group, stock_uom,
|
# item = webnotes.conn.sql("""select description, item_name, brand, item_group, stock_uom,
|
||||||
default_warehouse, default_income_account, default_sales_cost_center,
|
# default_warehouse, default_income_account, default_sales_cost_center,
|
||||||
purchase_account, description_html, barcode from `tabItem`
|
# purchase_account, description_html, barcode from `tabItem`
|
||||||
where name = %s and (ifnull(end_of_life,'')='' or end_of_life > now()
|
# where name = %s and (ifnull(end_of_life,'')='' or end_of_life > now()
|
||||||
or end_of_life = '0000-00-00') and (is_sales_item = 'Yes'
|
# or end_of_life = '0000-00-00') and (is_sales_item = 'Yes'
|
||||||
or is_service_item = 'Yes')""", args['item_code'], as_dict=1)
|
# or is_service_item = 'Yes')""", args['item_code'], as_dict=1)
|
||||||
tax = webnotes.conn.sql("""select tax_type, tax_rate from `tabItem Tax`
|
# tax = webnotes.conn.sql("""select tax_type, tax_rate from `tabItem Tax`
|
||||||
where parent = %s""", args['item_code'])
|
# where parent = %s""", args['item_code'])
|
||||||
t = {}
|
# t = {}
|
||||||
for x in tax: t[x[0]] = flt(x[1])
|
# for x in tax: t[x[0]] = flt(x[1])
|
||||||
ret = {
|
# ret = {
|
||||||
'description': item and item[0]['description_html'] or \
|
# 'description': item and item[0]['description_html'] or \
|
||||||
item[0]['description'],
|
# item[0]['description'],
|
||||||
'barcode': item and item[0]['barcode'] or '',
|
# 'barcode': item and item[0]['barcode'] or '',
|
||||||
'item_group': item and item[0]['item_group'] or '',
|
# 'item_group': item and item[0]['item_group'] or '',
|
||||||
'item_name': item and item[0]['item_name'] or '',
|
# 'item_name': item and item[0]['item_name'] or '',
|
||||||
'brand': item and item[0]['brand'] or '',
|
# 'brand': item and item[0]['brand'] or '',
|
||||||
'stock_uom': item and item[0]['stock_uom'] or '',
|
# 'stock_uom': item and item[0]['stock_uom'] or '',
|
||||||
'reserved_warehouse': item and item[0]['default_warehouse'] or '',
|
# 'reserved_warehouse': item and item[0]['default_warehouse'] or '',
|
||||||
'warehouse': item and item[0]['default_warehouse'] or \
|
# 'warehouse': item and item[0]['default_warehouse'] or \
|
||||||
args.get('warehouse'),
|
# args.get('warehouse'),
|
||||||
'income_account': item and item[0]['default_income_account'] or \
|
# 'income_account': item and item[0]['default_income_account'] or \
|
||||||
args.get('income_account'),
|
# args.get('income_account'),
|
||||||
'expense_account': item and item[0]['purchase_account'] or \
|
# 'expense_account': item and item[0]['purchase_account'] or \
|
||||||
args.get('expense_account'),
|
# args.get('expense_account'),
|
||||||
'cost_center': item and item[0]['default_sales_cost_center'] or \
|
# 'cost_center': item and item[0]['default_sales_cost_center'] or \
|
||||||
args.get('cost_center'),
|
# args.get('cost_center'),
|
||||||
# this is done coz if item once fetched is fetched again than its qty shld be reset to 1
|
# # this is done coz if item once fetched is fetched again than its qty shld be reset to 1
|
||||||
'qty': 1.00,
|
# 'qty': 1.00,
|
||||||
'adj_rate': 0,
|
# 'adj_rate': 0,
|
||||||
'amount': 0,
|
# 'amount': 0,
|
||||||
'export_amount': 0,
|
# 'export_amount': 0,
|
||||||
'item_tax_rate': json.dumps(t),
|
# 'item_tax_rate': json.dumps(t),
|
||||||
'batch_no': ''
|
# 'batch_no': ''
|
||||||
}
|
# }
|
||||||
if(obj.doc.price_list_name and item): #this is done to fetch the changed BASIC RATE and REF RATE based on PRICE LIST
|
# if(obj.doc.price_list_name and item): #this is done to fetch the changed BASIC RATE and REF RATE based on PRICE LIST
|
||||||
base_ref_rate = self.get_ref_rate(args['item_code'], obj.doc.price_list_name, obj.doc.price_list_currency, obj.doc.plc_conversion_rate)
|
# base_ref_rate = self.get_ref_rate(args['item_code'], obj.doc.price_list_name, obj.doc.price_list_currency, obj.doc.plc_conversion_rate)
|
||||||
ret['ref_rate'] = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
# ret['ref_rate'] = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
||||||
ret['export_rate'] = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
# ret['export_rate'] = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
||||||
ret['base_ref_rate'] = flt(base_ref_rate)
|
# ret['base_ref_rate'] = flt(base_ref_rate)
|
||||||
ret['basic_rate'] = flt(base_ref_rate)
|
# ret['basic_rate'] = flt(base_ref_rate)
|
||||||
|
#
|
||||||
if ret['warehouse'] or ret['reserved_warehouse']:
|
# if ret['warehouse'] or ret['reserved_warehouse']:
|
||||||
av_qty = self.get_available_qty({'item_code': args['item_code'], 'warehouse': ret['warehouse'] or ret['reserved_warehouse']})
|
# av_qty = self.get_available_qty({'item_code': args['item_code'], 'warehouse': ret['warehouse'] or ret['reserved_warehouse']})
|
||||||
ret.update(av_qty)
|
# ret.update(av_qty)
|
||||||
|
#
|
||||||
# get customer code for given item from Item Customer Detail
|
# # get customer code for given item from Item Customer Detail
|
||||||
customer_item_code_row = webnotes.conn.sql("""\
|
# customer_item_code_row = webnotes.conn.sql("""\
|
||||||
select ref_code from `tabItem Customer Detail`
|
# select ref_code from `tabItem Customer Detail`
|
||||||
where parent = %s and customer_name = %s""",
|
# where parent = %s and customer_name = %s""",
|
||||||
(args['item_code'], obj.doc.customer))
|
# (args['item_code'], obj.doc.customer))
|
||||||
if customer_item_code_row and customer_item_code_row[0][0]:
|
# if customer_item_code_row and customer_item_code_row[0][0]:
|
||||||
ret['customer_item_code'] = customer_item_code_row[0][0]
|
# ret['customer_item_code'] = customer_item_code_row[0][0]
|
||||||
|
#
|
||||||
return ret
|
# return ret
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: deprecate it
|
||||||
def get_item_defaults(self, args):
|
def get_item_defaults(self, args):
|
||||||
item = webnotes.conn.sql("""select default_warehouse, default_income_account,
|
item = webnotes.conn.sql("""select default_warehouse, default_income_account,
|
||||||
default_sales_cost_center, purchase_account from `tabItem` where name = %s
|
default_sales_cost_center, purchase_account from `tabItem` where name = %s
|
||||||
@ -200,97 +183,78 @@ class DocType(TransactionBase):
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def get_available_qty(self,args):
|
# def get_available_qty(self,args):
|
||||||
tot_avail_qty = webnotes.conn.sql("select projected_qty, actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (args['item_code'], args['warehouse']), as_dict=1)
|
# tot_avail_qty = webnotes.conn.sql("select projected_qty, actual_qty from `tabBin` where item_code = '%s' and warehouse = '%s'" % (args['item_code'], args['warehouse']), as_dict=1)
|
||||||
ret = {
|
# ret = {
|
||||||
'projected_qty' : tot_avail_qty and flt(tot_avail_qty[0]['projected_qty']) or 0,
|
# 'projected_qty' : tot_avail_qty and flt(tot_avail_qty[0]['projected_qty']) or 0,
|
||||||
'actual_qty' : tot_avail_qty and flt(tot_avail_qty[0]['actual_qty']) or 0
|
# 'actual_qty' : tot_avail_qty and flt(tot_avail_qty[0]['actual_qty']) or 0
|
||||||
}
|
# }
|
||||||
return ret
|
# return ret
|
||||||
|
|
||||||
|
|
||||||
# ***************** Get Ref rate as entered in Item Master ********************
|
# ***************** Get Ref rate as entered in Item Master ********************
|
||||||
def get_ref_rate(self, item_code, price_list_name, price_list_currency, plc_conv_rate):
|
# def get_ref_rate(self, item_code, price_list_name, price_list_currency, plc_conv_rate):
|
||||||
ref_rate = webnotes.conn.sql("select ref_rate from `tabItem Price` where parent = %s and price_list_name = %s and ref_currency = %s and selling=1",
|
# ref_rate = webnotes.conn.sql("select ref_rate from `tabItem Price` where parent = %s and price_list_name = %s and ref_currency = %s and selling=1",
|
||||||
(item_code, price_list_name, price_list_currency))
|
# (item_code, price_list_name, price_list_currency))
|
||||||
base_ref_rate = ref_rate and flt(ref_rate[0][0]) * flt(plc_conv_rate) or 0
|
# base_ref_rate = ref_rate and flt(ref_rate[0][0]) * flt(plc_conv_rate) or 0
|
||||||
return base_ref_rate
|
# return base_ref_rate
|
||||||
|
|
||||||
def get_barcode_details(self, barcode):
|
|
||||||
item = webnotes.conn.sql("select name, end_of_life, is_sales_item, is_service_item \
|
|
||||||
from `tabItem` where barcode = %s", barcode, as_dict=1)
|
|
||||||
ret = {}
|
|
||||||
if not item:
|
|
||||||
msgprint("""No item found for this barcode: %s.
|
|
||||||
May be barcode not updated in item master. Please check""" % barcode)
|
|
||||||
elif item[0]['end_of_life'] and getdate(cstr(item[0]['end_of_life'])) < nowdate():
|
|
||||||
msgprint("Item: %s has been expired. Please check 'End of Life' field in item master" % item[0]['name'])
|
|
||||||
elif item[0]['is_sales_item'] == 'No' and item[0]['is_service_item'] == 'No':
|
|
||||||
msgprint("Item: %s is not a sales or service item" % item[0]['name'])
|
|
||||||
elif len(item) > 1:
|
|
||||||
msgprint("There are multiple item for this barcode. \nPlease select item code manually")
|
|
||||||
else:
|
|
||||||
ret = {'item_code': item and item[0]['name'] or ''}
|
|
||||||
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
# ****** Re-cancellculates Basic Rate & amount based on Price List Selected ******
|
# ****** Re-cancellculates Basic Rate & amount based on Price List Selected ******
|
||||||
def get_adj_percent(self, obj):
|
# def get_adj_percent(self, obj):
|
||||||
for d in getlist(obj.doclist, obj.fname):
|
# for d in getlist(obj.doclist, obj.fname):
|
||||||
base_ref_rate = self.get_ref_rate(d.item_code, obj.doc.price_list_name, obj.doc.price_list_currency, obj.doc.plc_conversion_rate)
|
# base_ref_rate = self.get_ref_rate(d.item_code, obj.doc.price_list_name, obj.doc.price_list_currency, obj.doc.plc_conversion_rate)
|
||||||
d.adj_rate = 0
|
# d.adj_rate = 0
|
||||||
d.ref_rate = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
# d.ref_rate = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
||||||
d.basic_rate = flt(base_ref_rate)
|
# d.basic_rate = flt(base_ref_rate)
|
||||||
d.base_ref_rate = flt(base_ref_rate)
|
# d.base_ref_rate = flt(base_ref_rate)
|
||||||
d.export_rate = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
# d.export_rate = flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
||||||
d.amount = flt(d.qty)*flt(base_ref_rate)
|
# d.amount = flt(d.qty)*flt(base_ref_rate)
|
||||||
d.export_amount = flt(d.qty)*flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
# d.export_amount = flt(d.qty)*flt(base_ref_rate)/flt(obj.doc.conversion_rate)
|
||||||
|
|
||||||
|
|
||||||
# Load Default Taxes
|
# # Load Default Taxes
|
||||||
# ====================
|
# # ====================
|
||||||
def load_default_taxes(self, obj):
|
# def load_default_taxes(self, obj):
|
||||||
if cstr(obj.doc.charge):
|
# if cstr(obj.doc.charge):
|
||||||
return self.get_other_charges(obj)
|
# return self.get_other_charges(obj)
|
||||||
else:
|
# else:
|
||||||
return self.get_other_charges(obj, 1)
|
# return self.get_other_charges(obj, 1)
|
||||||
|
#
|
||||||
|
#
|
||||||
# Get other charges from Master
|
# # Get other charges from Master
|
||||||
# =================================================================================
|
# # =================================================================================
|
||||||
def get_other_charges(self,obj, default=0):
|
# def get_other_charges(self,obj, default=0):
|
||||||
obj.doclist = obj.doc.clear_table(obj.doclist, 'other_charges')
|
# obj.doclist = obj.doc.clear_table(obj.doclist, 'other_charges')
|
||||||
if not getlist(obj.doclist, 'other_charges'):
|
# if not getlist(obj.doclist, 'other_charges'):
|
||||||
if default: add_cond = 'ifnull(t2.is_default,0) = 1'
|
# if default: add_cond = 'ifnull(t2.is_default,0) = 1'
|
||||||
else: add_cond = 't1.parent = "'+cstr(obj.doc.charge)+'"'
|
# else: add_cond = 't1.parent = "'+cstr(obj.doc.charge)+'"'
|
||||||
idx = 0
|
# idx = 0
|
||||||
other_charge = webnotes.conn.sql("""\
|
# other_charge = webnotes.conn.sql("""\
|
||||||
select t1.*
|
# select t1.*
|
||||||
from
|
# from
|
||||||
`tabSales Taxes and Charges` t1,
|
# `tabSales Taxes and Charges` t1,
|
||||||
`tabSales Taxes and Charges Master` t2
|
# `tabSales Taxes and Charges Master` t2
|
||||||
where
|
# where
|
||||||
t1.parent = t2.name and
|
# t1.parent = t2.name and
|
||||||
t2.company = '%s' and
|
# t2.company = '%s' and
|
||||||
%s
|
# %s
|
||||||
order by t1.idx""" % (obj.doc.company, add_cond), as_dict=1)
|
# order by t1.idx""" % (obj.doc.company, add_cond), as_dict=1)
|
||||||
from webnotes.model import default_fields
|
# from webnotes.model import default_fields
|
||||||
for other in other_charge:
|
# for other in other_charge:
|
||||||
# remove default fields like parent, parenttype etc.
|
# # remove default fields like parent, parenttype etc.
|
||||||
# from query results
|
# # from query results
|
||||||
for field in default_fields:
|
# for field in default_fields:
|
||||||
if field in other: del other[field]
|
# if field in other: del other[field]
|
||||||
|
#
|
||||||
d = addchild(obj.doc, 'other_charges', 'Sales Taxes and Charges',
|
# d = addchild(obj.doc, 'other_charges', 'Sales Taxes and Charges',
|
||||||
obj.doclist)
|
# obj.doclist)
|
||||||
d.fields.update(other)
|
# d.fields.update(other)
|
||||||
d.rate = flt(d.rate)
|
# d.rate = flt(d.rate)
|
||||||
d.tax_amount = flt(d.tax_rate)
|
# d.tax_amount = flt(d.tax_rate)
|
||||||
d.included_in_print_rate = cint(d.included_in_print_rate)
|
# d.included_in_print_rate = cint(d.included_in_print_rate)
|
||||||
d.idx = idx
|
# d.idx = idx
|
||||||
idx += 1
|
# idx += 1
|
||||||
return obj.doclist
|
# return obj.doclist
|
||||||
|
|
||||||
# Get TERMS AND CONDITIONS
|
# Get TERMS AND CONDITIONS
|
||||||
# =======================================================================================
|
# =======================================================================================
|
||||||
@ -327,23 +291,6 @@ class DocType(TransactionBase):
|
|||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
# Get Commission rate
|
|
||||||
# =======================================================================
|
|
||||||
def get_comm_rate(self, sales_partner, obj):
|
|
||||||
|
|
||||||
comm_rate = webnotes.conn.sql("select commission_rate from `tabSales Partner` where name = '%s' and docstatus != 2" %(sales_partner), as_dict=1)
|
|
||||||
if comm_rate:
|
|
||||||
total_comm = flt(comm_rate[0]['commission_rate']) * flt(obj.doc.net_total) / 100
|
|
||||||
ret = {
|
|
||||||
'commission_rate' : comm_rate and flt(comm_rate[0]['commission_rate']) or 0,
|
|
||||||
'total_commission' : flt(total_comm)
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
else:
|
|
||||||
msgprint("Business Associate : %s does not exist in the system." % (sales_partner))
|
|
||||||
raise Exception
|
|
||||||
|
|
||||||
|
|
||||||
# To verify whether rate entered in details table does not exceed max discount %
|
# To verify whether rate entered in details table does not exceed max discount %
|
||||||
# =======================================================================================
|
# =======================================================================================
|
||||||
def validate_max_discount(self,obj, detail_table):
|
def validate_max_discount(self,obj, detail_table):
|
||||||
@ -352,16 +299,6 @@ class DocType(TransactionBase):
|
|||||||
if discount and discount[0]['max_discount'] and (flt(d.adj_rate)>flt(discount[0]['max_discount'])):
|
if discount and discount[0]['max_discount'] and (flt(d.adj_rate)>flt(discount[0]['max_discount'])):
|
||||||
msgprint("You cannot give more than " + cstr(discount[0]['max_discount']) + " % discount on Item Code : "+cstr(d.item_code))
|
msgprint("You cannot give more than " + cstr(discount[0]['max_discount']) + " % discount on Item Code : "+cstr(d.item_code))
|
||||||
raise Exception
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
# Get sum of allocated % of sales person (it should be 100%)
|
|
||||||
# ========================================================================
|
|
||||||
# it indicates % contribution of sales person in sales
|
|
||||||
def get_allocated_sum(self,obj):
|
|
||||||
sales_team_list = obj.doclist.get({"parentfield": "sales_team"})
|
|
||||||
total_allocation = sum([flt(d.allocated_percentage) for d in sales_team_list])
|
|
||||||
if sales_team_list and total_allocation != 100.0:
|
|
||||||
msgprint("Total Allocated % of Sales Persons should be 100%", raise_exception=True)
|
|
||||||
|
|
||||||
# Check Conversion Rate (i.e. it will not allow conversion rate to be 1 for Currency other than default currency set in Global Defaults)
|
# Check Conversion Rate (i.e. it will not allow conversion rate to be 1 for Currency other than default currency set in Global Defaults)
|
||||||
# ===========================================================================
|
# ===========================================================================
|
||||||
|
@ -83,12 +83,6 @@ class DocType(SellingController):
|
|||||||
def get_rate(self,arg):
|
def get_rate(self,arg):
|
||||||
return get_obj('Sales Common').get_rate(arg)
|
return get_obj('Sales Common').get_rate(arg)
|
||||||
|
|
||||||
def load_default_taxes(self):
|
|
||||||
self.doclist = get_obj('Sales Common').load_default_taxes(self)
|
|
||||||
|
|
||||||
def get_other_charges(self):
|
|
||||||
self.doclist = get_obj('Sales Common').get_other_charges(self)
|
|
||||||
|
|
||||||
def get_tc_details(self):
|
def get_tc_details(self):
|
||||||
return get_obj('Sales Common').get_tc_details(self)
|
return get_obj('Sales Common').get_tc_details(self)
|
||||||
|
|
||||||
@ -225,7 +219,6 @@ class DocType(SellingController):
|
|||||||
sales_com_obj.check_conversion_rate(self)
|
sales_com_obj.check_conversion_rate(self)
|
||||||
|
|
||||||
sales_com_obj.validate_max_discount(self,'sales_order_details')
|
sales_com_obj.validate_max_discount(self,'sales_order_details')
|
||||||
sales_com_obj.get_allocated_sum(self)
|
|
||||||
self.doclist = sales_com_obj.make_packing_list(self,'sales_order_details')
|
self.doclist = sales_com_obj.make_packing_list(self,'sales_order_details')
|
||||||
|
|
||||||
if not self.doc.status:
|
if not self.doc.status:
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-05-06 12:03:43",
|
"creation": "2013-05-21 16:16:41",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-05-06 13:06:37",
|
"modified": "2013-05-21 18:30:14",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -230,7 +230,8 @@
|
|||||||
"oldfieldname": "sales_order_details",
|
"oldfieldname": "sales_order_details",
|
||||||
"oldfieldtype": "Table",
|
"oldfieldtype": "Table",
|
||||||
"options": "Sales Order Item",
|
"options": "Sales Order Item",
|
||||||
"print_hide": 0
|
"print_hide": 0,
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@ -434,7 +435,7 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "other_charges_total",
|
"fieldname": "other_charges_total",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"label": "Taxes and Charges Total*",
|
"label": "Taxes and Charges Total",
|
||||||
"oldfieldname": "other_charges_total",
|
"oldfieldname": "other_charges_total",
|
||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
@ -442,6 +443,15 @@
|
|||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
"width": "150px"
|
"width": "150px"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"doctype": "DocField",
|
||||||
|
"fieldname": "other_charges_total_export",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"label": "Taxes and Charges Total (Export)",
|
||||||
|
"options": "company",
|
||||||
|
"print_hide": 1,
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "other_charges_calculation",
|
"fieldname": "other_charges_calculation",
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-02-22 01:27:52",
|
"creation": "2013-04-19 13:30:51",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-03-07 07:03:30",
|
"modified": "2013-05-21 16:44:41",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -109,6 +109,7 @@
|
|||||||
"options": "currency",
|
"options": "currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"print_width": "70px",
|
"print_width": "70px",
|
||||||
|
"read_only": 1,
|
||||||
"reqd": 0,
|
"reqd": 0,
|
||||||
"width": "70px"
|
"width": "70px"
|
||||||
},
|
},
|
||||||
@ -176,6 +177,7 @@
|
|||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"print_width": "100px",
|
"print_width": "100px",
|
||||||
|
"read_only": 1,
|
||||||
"reqd": 0,
|
"reqd": 0,
|
||||||
"width": "100px"
|
"width": "100px"
|
||||||
},
|
},
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-02-22 01:27:53",
|
"creation": "2013-04-19 13:30:51",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-03-07 07:03:31",
|
"modified": "2013-05-21 17:04:45",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -42,6 +42,7 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "sales_designation",
|
"fieldname": "sales_designation",
|
||||||
"fieldtype": "Data",
|
"fieldtype": "Data",
|
||||||
|
"hidden": 0,
|
||||||
"label": "Designation",
|
"label": "Designation",
|
||||||
"oldfieldname": "sales_designation",
|
"oldfieldname": "sales_designation",
|
||||||
"oldfieldtype": "Data",
|
"oldfieldtype": "Data",
|
||||||
@ -63,7 +64,7 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "allocated_percentage",
|
"fieldname": "allocated_percentage",
|
||||||
"fieldtype": "Float",
|
"fieldtype": "Float",
|
||||||
"label": "Allocated (%)",
|
"label": "Contribution (%)",
|
||||||
"oldfieldname": "allocated_percentage",
|
"oldfieldname": "allocated_percentage",
|
||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"print_width": "100px",
|
"print_width": "100px",
|
||||||
@ -74,11 +75,12 @@
|
|||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "allocated_amount",
|
"fieldname": "allocated_amount",
|
||||||
"fieldtype": "Currency",
|
"fieldtype": "Currency",
|
||||||
"label": "Allocated Amount",
|
"label": "Contribution to Net Total",
|
||||||
"oldfieldname": "allocated_amount",
|
"oldfieldname": "allocated_amount",
|
||||||
"oldfieldtype": "Currency",
|
"oldfieldtype": "Currency",
|
||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
"print_width": "120px",
|
"print_width": "120px",
|
||||||
|
"read_only": 1,
|
||||||
"reqd": 0,
|
"reqd": 0,
|
||||||
"width": "120px"
|
"width": "120px"
|
||||||
},
|
},
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes import msgprint, _
|
from webnotes import msgprint, _
|
||||||
from webnotes.utils import flt
|
from webnotes.utils import flt, cint, comma_and
|
||||||
import json
|
import json
|
||||||
|
|
||||||
def get_customer_list(doctype, txt, searchfield, start, page_len, filters):
|
def get_customer_list(doctype, txt, searchfield, start, page_len, filters):
|
||||||
@ -51,22 +51,45 @@ def get_item_details(args):
|
|||||||
args = json.loads(args)
|
args = json.loads(args)
|
||||||
args = webnotes._dict(args)
|
args = webnotes._dict(args)
|
||||||
|
|
||||||
|
if args.barcode:
|
||||||
|
args.item_code = _get_item_code(args.barcode)
|
||||||
|
|
||||||
item_bean = webnotes.bean("Item", args.item_code)
|
item_bean = webnotes.bean("Item", args.item_code)
|
||||||
|
|
||||||
_validate_item_details(args, item_bean.doc)
|
_validate_item_details(args, item_bean.doc)
|
||||||
|
|
||||||
out = _get_basic_details(args, item_bean)
|
out = _get_basic_details(args, item_bean)
|
||||||
|
|
||||||
if args.price_list_name and args.price_list_currency:
|
meta = webnotes.get_doctype(args.doctype)
|
||||||
out.update(_get_price_list_rate(args, item_bean))
|
if meta.get_field("currency"):
|
||||||
|
out.base_ref_rate = out.basic_rate = out.ref_rate = out.export_rate = 0.0
|
||||||
|
|
||||||
|
if args.price_list_name and args.price_list_currency:
|
||||||
|
out.update(_get_price_list_rate(args, item_bean, meta))
|
||||||
|
|
||||||
if out.warehouse or out.reserved_warehouse:
|
if out.warehouse or out.reserved_warehouse:
|
||||||
out.update(_get_available_qty(args, out.warehouse or out.reserved_warehouse))
|
out.update(_get_available_qty(args, out.warehouse or out.reserved_warehouse))
|
||||||
|
|
||||||
out.customer_item_code = _get_customer_item_code(args, item_bean)
|
out.customer_item_code = _get_customer_item_code(args, item_bean)
|
||||||
|
|
||||||
|
if cint(args.is_pos):
|
||||||
|
pos_settings = get_pos_settings(args.company)
|
||||||
|
out.update(apply_pos_settings(pos_settings, out))
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
def _get_item_code(barcode):
|
||||||
|
item_code = webnotes.conn.sql_list("""select name from `tabItem` where barcode=%s""", barcode)
|
||||||
|
|
||||||
|
if not item_code:
|
||||||
|
msgprint(_("No Item found with Barcode") + ": %s" % barcode, raise_exception=True)
|
||||||
|
|
||||||
|
elif len(item_code) > 1:
|
||||||
|
msgprint(_("Items") + " %s " % comma_and(item_code) +
|
||||||
|
_("have the same Barcode") + " %s" % barcode, raise_exception=True)
|
||||||
|
|
||||||
|
return item_code[0]
|
||||||
|
|
||||||
def _validate_item_details(args, item):
|
def _validate_item_details(args, item):
|
||||||
from utilities.transaction_base import validate_item_fetch
|
from utilities.transaction_base import validate_item_fetch
|
||||||
validate_item_fetch(args, item)
|
validate_item_fetch(args, item)
|
||||||
@ -106,18 +129,21 @@ def _get_basic_details(args, item_bean):
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def _get_price_list_rate(args, item_bean):
|
def _get_price_list_rate(args, item_bean, meta=None):
|
||||||
base_ref_rate = item_bean.doclist.get({
|
base_ref_rate = item_bean.doclist.get({
|
||||||
"parentfield": "ref_rate_details",
|
"parentfield": "ref_rate_details",
|
||||||
"price_list_name": args.price_list_name,
|
"price_list_name": args.price_list_name,
|
||||||
"price_list_currency": args.price_list_currency,
|
"price_list_currency": args.price_list_currency,
|
||||||
"selling": 1})
|
"selling": 1})
|
||||||
out = webnotes._dict()
|
|
||||||
out.base_ref_rate = flt(base_ref_rate[0].ref_rate) if base_ref_rate else 0.0
|
if not base_ref_rate:
|
||||||
out.basic_rate = out.base_ref_rate
|
return {}
|
||||||
out.ref_rate = out.base_ref_rate / flt(args.conversion_rate)
|
|
||||||
out.export_rate = out.ref_rate
|
# found price list rate - now we can validate
|
||||||
return out
|
from utilities.transaction_base import validate_currency
|
||||||
|
validate_currency(args, item_bean.doc, meta)
|
||||||
|
|
||||||
|
return {"base_ref_rate": flt(base_ref_rate[0].ref_rate / args.plc_conversion_rate)}
|
||||||
|
|
||||||
def _get_available_qty(args, warehouse):
|
def _get_available_qty(args, warehouse):
|
||||||
return webnotes.conn.get_value("Bin", {"item_code": args.item_code, "warehouse": warehouse},
|
return webnotes.conn.get_value("Bin", {"item_code": args.item_code, "warehouse": warehouse},
|
||||||
@ -128,4 +154,25 @@ def _get_customer_item_code(args, item_bean):
|
|||||||
"customer_name": args.customer})
|
"customer_name": args.customer})
|
||||||
|
|
||||||
return customer_item_code and customer_item_code[0].ref_code or None
|
return customer_item_code and customer_item_code[0].ref_code or None
|
||||||
|
|
||||||
|
def get_pos_settings(company):
|
||||||
|
pos_settings = webnotes.conn.sql("""select * from `tabPOS Setting` where user = %s
|
||||||
|
and company = %s""", (webnotes.session['user'], company), as_dict=1)
|
||||||
|
|
||||||
|
if not pos_settings:
|
||||||
|
pos_settings = webnotes.conn.sql("""select * from `tabPOS Setting`
|
||||||
|
where ifnull(user,'') = '' and company = %s""", company, as_dict=1)
|
||||||
|
|
||||||
|
return pos_settings and pos_settings[0] or None
|
||||||
|
|
||||||
|
def apply_pos_settings(pos_settings, opts):
|
||||||
|
out = {}
|
||||||
|
|
||||||
|
for fieldname in ("income_account", "cost_center", "warehouse", "expense_account"):
|
||||||
|
if not opts.get(fieldname):
|
||||||
|
out[fieldname] = pos_settings.get(fieldname)
|
||||||
|
|
||||||
|
if out.get("warehouse"):
|
||||||
|
out["actual_qty"] = _get_available_qty(opts, out.get("warehouse")).get("actual_qty")
|
||||||
|
|
||||||
|
return out
|
||||||
|
@ -114,16 +114,6 @@ class DocType(SellingController):
|
|||||||
def get_rate(self,arg):
|
def get_rate(self,arg):
|
||||||
return get_obj('Sales Common').get_rate(arg)
|
return get_obj('Sales Common').get_rate(arg)
|
||||||
|
|
||||||
|
|
||||||
def load_default_taxes(self):
|
|
||||||
self.doclist = get_obj('Sales Common').load_default_taxes(self)
|
|
||||||
|
|
||||||
|
|
||||||
def get_other_charges(self):
|
|
||||||
"""Pull details from Sales Taxes and Charges Master"""
|
|
||||||
self.doclist = get_obj('Sales Common').get_other_charges(self)
|
|
||||||
|
|
||||||
|
|
||||||
def so_required(self):
|
def so_required(self):
|
||||||
"""check in manage account if sales order required or not"""
|
"""check in manage account if sales order required or not"""
|
||||||
if webnotes.conn.get_value('Global Defaults', 'Global Defaults', 'so_required') == 'Yes':
|
if webnotes.conn.get_value('Global Defaults', 'Global Defaults', 'so_required') == 'Yes':
|
||||||
@ -152,7 +142,6 @@ class DocType(SellingController):
|
|||||||
self.validate_warehouse()
|
self.validate_warehouse()
|
||||||
|
|
||||||
sales_com_obj.validate_max_discount(self, 'delivery_note_details')
|
sales_com_obj.validate_max_discount(self, 'delivery_note_details')
|
||||||
sales_com_obj.get_allocated_sum(self)
|
|
||||||
sales_com_obj.check_conversion_rate(self)
|
sales_com_obj.check_conversion_rate(self)
|
||||||
|
|
||||||
# Set actual qty for each item in selected warehouse
|
# Set actual qty for each item in selected warehouse
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-05-06 12:03:30",
|
"creation": "2013-05-21 16:16:31",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-05-06 13:08:13",
|
"modified": "2013-05-21 18:30:32",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -223,7 +223,8 @@
|
|||||||
"oldfieldtype": "Table",
|
"oldfieldtype": "Table",
|
||||||
"options": "Delivery Note Item",
|
"options": "Delivery Note Item",
|
||||||
"print_hide": 0,
|
"print_hide": 0,
|
||||||
"read_only": 0
|
"read_only": 0,
|
||||||
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
@ -443,6 +444,15 @@
|
|||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
"width": "150px"
|
"width": "150px"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"doctype": "DocField",
|
||||||
|
"fieldname": "other_charges_total_export",
|
||||||
|
"fieldtype": "Currency",
|
||||||
|
"label": "Taxes and Charges Total (Export)",
|
||||||
|
"options": "company",
|
||||||
|
"print_hide": 1,
|
||||||
|
"read_only": 1
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "calculate_charges",
|
"fieldname": "calculate_charges",
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"creation": "2013-04-01 10:49:21",
|
"creation": "2013-04-19 13:31:02",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-04-17 17:20:58",
|
"modified": "2013-05-21 16:47:16",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -120,7 +120,7 @@
|
|||||||
"options": "currency",
|
"options": "currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"print_width": "100px",
|
"print_width": "100px",
|
||||||
"read_only": 0,
|
"read_only": 1,
|
||||||
"reqd": 0,
|
"reqd": 0,
|
||||||
"width": "100px"
|
"width": "100px"
|
||||||
},
|
},
|
||||||
@ -189,7 +189,7 @@
|
|||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"print_width": "150px",
|
"print_width": "150px",
|
||||||
"read_only": 0,
|
"read_only": 1,
|
||||||
"reqd": 0,
|
"reqd": 0,
|
||||||
"width": "150px"
|
"width": "150px"
|
||||||
},
|
},
|
||||||
|
@ -297,14 +297,17 @@ def validate_item_fetch(args, item):
|
|||||||
if not args.company:
|
if not args.company:
|
||||||
msgprint(_("Please specify Company"), raise_exception=True)
|
msgprint(_("Please specify Company"), raise_exception=True)
|
||||||
|
|
||||||
# validate conversion rates
|
def validate_currency(args, item, meta=None):
|
||||||
meta = webnotes.get_doctype(args.doctype)
|
if not meta:
|
||||||
|
meta = webnotes.get_doctype(args.doctype)
|
||||||
|
|
||||||
|
# validate conversion rate
|
||||||
if meta.get_field("currency"):
|
if meta.get_field("currency"):
|
||||||
# validate conversion rate
|
|
||||||
validate_conversion_rate(args.currency, args.conversion_rate,
|
validate_conversion_rate(args.currency, args.conversion_rate,
|
||||||
meta.get_label("conversion_rate"), args.company)
|
meta.get_label("conversion_rate"), args.company)
|
||||||
|
|
||||||
# validate price list conversion rate
|
# validate price list conversion rate
|
||||||
if args.price_list_name and args.price_list_currency:
|
if meta.get_field("price_list_currency") and args.price_list_name and \
|
||||||
validate_conversion_rate(args.price_list_currency, args.plc_conversion_rate,
|
args.price_list_currency:
|
||||||
meta.get_label("plc_conversion_rate"), args.company)
|
validate_conversion_rate(args.price_list_currency, args.plc_conversion_rate,
|
||||||
|
meta.get_label("plc_conversion_rate"), args.company)
|
Loading…
Reference in New Issue
Block a user