fixes in c-form
This commit is contained in:
parent
80c681294c
commit
1b4f56c57f
@ -18,11 +18,7 @@ from __future__ import unicode_literals
|
|||||||
import webnotes
|
import webnotes
|
||||||
from webnotes.utils import flt, getdate
|
from webnotes.utils import flt, getdate
|
||||||
from webnotes.model.doc import make_autoname
|
from webnotes.model.doc import make_autoname
|
||||||
from webnotes.model.wrapper import getlist, copy_doclist
|
from webnotes.model.wrapper import getlist
|
||||||
from webnotes import msgprint
|
|
||||||
|
|
||||||
sql = webnotes.conn.sql
|
|
||||||
|
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self,d,dl):
|
def __init__(self,d,dl):
|
||||||
@ -31,53 +27,57 @@ class DocType:
|
|||||||
def autoname(self):
|
def autoname(self):
|
||||||
self.doc.name = make_autoname(self.doc.naming_series + '.#####')
|
self.doc.name = make_autoname(self.doc.naming_series + '.#####')
|
||||||
|
|
||||||
|
def validate(self):
|
||||||
|
"""Validate invoice that c-form is applicable
|
||||||
|
and no other c-form is received for that"""
|
||||||
|
|
||||||
|
for d in getlist(self.doclist, 'invoice_details'):
|
||||||
|
inv = webnotes.conn.sql("""select c_form_applicable, c_form_no from
|
||||||
|
`tabSales Invoice` where name = %s""", d.invoice_no)
|
||||||
|
|
||||||
|
if not inv:
|
||||||
|
webnotes.msgprint("Invoice: %s is not exists in the system, please check." %
|
||||||
|
d.invoice_no, raise_exception=1)
|
||||||
|
|
||||||
|
elif inv[0][0] != 'Yes':
|
||||||
|
webnotes.msgprint("C-form is not applicable for Invoice: %s" %
|
||||||
|
d.invoice_no, raise_exception=1)
|
||||||
|
|
||||||
|
elif inv[0][1] and inv[0][1] != self.doc.name:
|
||||||
|
webnotes.msgprint("""Invoice %s is tagged in another C-form: %s.
|
||||||
|
If you want to change C-form no for this invoice,
|
||||||
|
please remove invoice no from the previous c-form and then try again""" %
|
||||||
|
(d.invoice_no, inv[0][1]), raise_exception=1)
|
||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
""" Update C-Form No on invoices"""
|
""" Update C-Form No on invoices"""
|
||||||
|
inv = [d.invoice_no for d in getlist(self.doclist, 'invoice_details')]
|
||||||
|
if inv:
|
||||||
|
webnotes.conn.sql("""update `tabSales Invoice` set c_form_no=%s, modified=%s
|
||||||
|
where name in (%s)""" % ('%s', '%s', ', '.join(['%s'] * len(inv))),
|
||||||
|
tuple([self.doc.name, self.doc.modified] + inv), debug=1)
|
||||||
|
|
||||||
if len(getlist(self.doclist, 'invoice_details')):
|
webnotes.conn.sql("""update `tabSales Invoice` set c_form_no = '', modified = %s
|
||||||
inv = "'" + "', '".join([d.invoice_no for d in getlist(self.doclist, 'invoice_details')]) + "'"
|
where name not in (%s) and ifnull(c_form_no, '') = %s""" %
|
||||||
sql("""update `tabSales Invoice` set c_form_no = '%s', modified ='%s'
|
('%s', ', '.join(['%s'*len(inv)]), '%s'),
|
||||||
where name in (%s)"""%(self.doc.name, self.doc.modified, inv))
|
tuple([self.doc.modified] + inv + [self.doc.name]), debug=1)
|
||||||
sql("""update `tabSales Invoice` set c_form_no = '', modified = %s where name not
|
|
||||||
in (%s) and ifnull(c_form_no, '') = %s""", (self.doc.modified, self.doc.name, inv))
|
|
||||||
else:
|
else:
|
||||||
msgprint("Please enter atleast 1 invoice in the table below", raise_exception=1)
|
webnotes.msgprint("Please enter atleast 1 invoice in the table", raise_exception=1)
|
||||||
|
|
||||||
self.calculate_total_invoiced_amount()
|
self.set_total_invoiced_amount()
|
||||||
|
|
||||||
def calculate_total_invoiced_amount(self):
|
def set_total_invoiced_amount(self):
|
||||||
total = 0
|
total = sum([flt(d.total) for d in getlist(self.doclist, 'invoice_details')])
|
||||||
for d in getlist(self.doclist, 'invoice_details'):
|
|
||||||
total += flt(d.grand_total)
|
|
||||||
webnotes.conn.set(self.doc, 'total_invoiced_amount', total)
|
webnotes.conn.set(self.doc, 'total_invoiced_amount', total)
|
||||||
|
|
||||||
|
|
||||||
def get_invoice_details(self, invoice_no):
|
def get_invoice_details(self, invoice_no):
|
||||||
""" Pull details from invoices for referrence """
|
""" Pull details from invoices for referrence """
|
||||||
|
|
||||||
inv = sql("""select posting_date, territory, net_total, grand_total from
|
inv = webnotes.conn.sql("""select posting_date, territory, net_total, grand_total
|
||||||
`tabSales Invoice` where name = %s""", invoice_no)
|
from `tabSales Invoice` where name = %s""", invoice_no)
|
||||||
ret = {
|
return {
|
||||||
'invoice_date' : inv and getdate(inv[0][0]).strftime('%Y-%m-%d') or '',
|
'invoice_date' : inv and getdate(inv[0][0]).strftime('%Y-%m-%d') or '',
|
||||||
'territory' : inv and inv[0][1] or '',
|
'territory' : inv and inv[0][1] or '',
|
||||||
'net_total' : inv and flt(inv[0][2]) or '',
|
'net_total' : inv and flt(inv[0][2]) or '',
|
||||||
'grand_total' : inv and flt(inv[0][3]) or ''
|
'grand_total' : inv and flt(inv[0][3]) or ''
|
||||||
}
|
}
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def validate_invoice(self):
|
|
||||||
"""Validate invoice that c-form is applicable and no other c-form is
|
|
||||||
received for that"""
|
|
||||||
|
|
||||||
for d in getlist(self.doclist, 'invoice_details'):
|
|
||||||
inv = sql("""select c_form_applicable, c_form_no from
|
|
||||||
`tabSales Invoice` where name = %s""", invoice_no)
|
|
||||||
if not inv:
|
|
||||||
msgprint("Invoice: %s is not exists in the system, please check." % d.invoice_no, raise_exception=1)
|
|
||||||
elif inv[0][0] != 'Yes':
|
|
||||||
msgprint("C-form is not applicable for Invoice: %s" % d.invoice_no, raise_exception=1)
|
|
||||||
elif inv[0][1] and inv[0][1] != self.doc.name:
|
|
||||||
msgprint("""Invoice %s is tagged in another C-form: %s. \nIf you want to change C-form no for this invoice,
|
|
||||||
please remove invoice no from the previous c-form and then try again""" % (d.invoice_no, inv[0][1]), raise_exception=1)
|
|
||||||
|
@ -117,7 +117,7 @@ class DocType:
|
|||||||
from `tabDelivery Note Item` dni
|
from `tabDelivery Note Item` dni
|
||||||
where parent=%s and item_code in (%s)
|
where parent=%s and item_code in (%s)
|
||||||
group by item_code""" % ("%s", ", ".join(["%s"]*len(items))),
|
group by item_code""" % ("%s", ", ".join(["%s"]*len(items))),
|
||||||
tuple([self.doc.delivery_note] + items), as_dict=1, debug=1)
|
tuple([self.doc.delivery_note] + items), as_dict=1)
|
||||||
|
|
||||||
ps_item_qty = dict([[d.item_code, d.qty] for d in self.doclist])
|
ps_item_qty = dict([[d.item_code, d.qty] for d in self.doclist])
|
||||||
|
|
||||||
@ -170,9 +170,6 @@ class DocType:
|
|||||||
webnotes.msgprint("Invalid new packed quantity for item %s. \
|
webnotes.msgprint("Invalid new packed quantity for item %s. \
|
||||||
Please try again or contact support@erpnext.com" % item['item_code'], raise_exception=1)
|
Please try again or contact support@erpnext.com" % item['item_code'], raise_exception=1)
|
||||||
|
|
||||||
delivery_note_item = webnotes.conn.get_value("Delivery Note Item", {
|
|
||||||
"parent": self.doc.delivery_note, "item_code": item["item_code"]})
|
|
||||||
|
|
||||||
webnotes.conn.sql("""\
|
webnotes.conn.sql("""\
|
||||||
UPDATE `tabDelivery Note Item`
|
UPDATE `tabDelivery Note Item`
|
||||||
SET packed_qty = %s
|
SET packed_qty = %s
|
||||||
|
@ -56,14 +56,11 @@ def update_entries_after(args, verbose=1):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
if sle.serial_no:
|
if sle.serial_no:
|
||||||
valuation_rate = get_serialized_values(qty_after_transaction, sle,
|
valuation_rate = get_serialized_values(qty_after_transaction, sle, valuation_rate)
|
||||||
valuation_rate)
|
|
||||||
elif valuation_method == "Moving Average":
|
elif valuation_method == "Moving Average":
|
||||||
valuation_rate = get_moving_average_values(qty_after_transaction, sle,
|
valuation_rate = get_moving_average_values(qty_after_transaction, sle, valuation_rate)
|
||||||
valuation_rate)
|
|
||||||
else:
|
else:
|
||||||
valuation_rate = get_fifo_values(qty_after_transaction, sle,
|
valuation_rate = get_fifo_values(qty_after_transaction, sle, stock_queue)
|
||||||
stock_queue)
|
|
||||||
|
|
||||||
qty_after_transaction += flt(sle.actual_qty)
|
qty_after_transaction += flt(sle.actual_qty)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user