patch for item price and price list

This commit is contained in:
Akhilesh Darjee 2014-01-07 19:43:35 +05:30
parent 806017c92a
commit 029f698c65
8 changed files with 68 additions and 18 deletions

View File

@ -2,14 +2,14 @@
{ {
"creation": "2011-12-21 11:08:55", "creation": "2011-12-21 11:08:55",
"docstatus": 0, "docstatus": 0,
"modified": "2013-09-13 17:17:47", "modified": "2014-01-07 18:46:29",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
{ {
"doc_type": "Sales Invoice", "doc_type": "Sales Invoice",
"doctype": "Print Format", "doctype": "Print Format",
"html": "<html>\n<head>\n<!--Item Table, Totals and Other Charges-->\n<script>\nfunction get_print_format() {\n var oc = getchildren('Sales Invoice Item', doc.name, 'entries');\n\tvar rows = '<table width=\"100%\" cellpadding=\"0\" class=\"cart\">\\\n <tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>\\\n <tr>\\\n <td width=\"60%\" align=\"left\">ITEM NAME.</td>\\\n <td width=\"10%\" align=\"right\">QTY</td>\\\n <td width=\"30%\" align=\"right\">AMOUNT</td>\\\n </tr>\\\n <tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>';\n\tfor (var x=0; x<oc.length; x++) {\n console.log(oc[x].item_code!=oc[x].item_name);\n\t\trows += '<tr>\\\n <td align=\"left\">' + oc[x].item_code + \n (oc[x].item_code!=oc[x].item_name ? ('<br>' + oc[x].item_name) : '') + '</td>\\\n <td align=\"right\" style=\"vertical-align:top;\">' + oc[x].qty + '</td>\\\n <td align=\"right\" valign=\"top\">' + format_currency(oc[x].export_amount, doc.currency) + '</td>\\\n </tr>';\n\t}\n rows += '<tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>\\\n <tr>\\\n <td colspan=\"2\" align=\"right\">Net Total</td>\\\n <td align=\"right\">' + format_currency(doc.net_total_export, doc.currency) + '</td>\\\n </tr>';\n if (doc.other_charges_total_export != 0) {\n var taxes = wn.model.get_children(\"Sales Taxes and Charges\", doc.name, \"other_charges\", \"Sales Invoice\");\n\t\t$.each(taxes, function(i, d) {\n\t\t\trows += '<tr>\\\n \t\t\t\t<td colspan=\"2\" align=\"right\">' + d.description + '</td>\\\n \t\t\t\t<td style=\"text-align: right;\">' + format_currency(d.tax_amount / doc.conversion_rate, doc.currency) + '</td>\\\n \t\t\t<tr>';\n\t\t});\n }\n rows += '<tr>\\\n <td colspan=\"2\" align=\"right\" style=\"vertical-align:middle;\">Grand Total</td>\\\n <td align=\"right\"><hr width=\"90%\" align=\"right\">' + format_currency(doc.grand_total_export, doc.currency) + '<br>\\\n <hr width=\"90%\" align=\"right\"></td>\\\n </tr>\\\n <tr>\\\n <td align=\"center\" colspan=\"3\">Thank You. Please visit again.</td>\\\n </tr>\\\n </table>';\n\treturn rows;\n}\n</script>\n<style>\n table, tr, td, div, p {\n font-family: Monospace;\n line-height: 200%;\n }\n h1, h2, h3, h4, h5, h6 {\n text-align: center;\n }\n\t@media screen {\n\t\tbody {\n\t\t\twidth: 4in;\n\t\t}\n\t}\n</style>\n</head>\n\n<body>\n<table width=\"100%\" cellpadding=\"4\">\n <tr>\n <td align=\"left\">RECEIPT NO: <script>doc.name</script></td>\n <td align=\"right\">DATE: <script>date.str_to_user(doc.posting_date)</script></td>\n </tr>\n <tr>\n <td>M/s <script>doc.customer</script></td>\n </tr>\n</table>\n<!--Item Table & Totals-->\n<div><script>get_print_format();</script></div>\n</body>\n</html>\n", "html": "<html>\n<head>\n<!--Item Table, Totals and Other Charges-->\n<script>\nfunction get_print_format() {\n\tvar oc = getchildren('Sales Invoice Item', doc.name, 'entries');\n\tvar rows = '<table width=\"100%\" cellpadding=\"0\" class=\"cart\">\\\n <tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>\\\n <tr>\\\n <td width=\"60%\" align=\"left\">ITEM CODE/DESC.</td>\\\n <td width=\"10%\" align=\"right\">QTY</td>\\\n <td width=\"30%\" align=\"right\">RATE</td>\\\n </tr>\\\n <tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>';\n\tfor (var x=0; x<oc.length; x++) {\n\t\trows += '<tr>\\\n <td align=\"left\">' + oc[x].item_code + '<br>' + oc[x].item_name + '</td>\\\n <td align=\"right\" style=\"vertical-align:top;\">' + oc[x].qty + '</td>\\\n <td align=\"right\" valign=\"top\">' + format_currency(oc[x].export_amount) + '</td>\\\n </tr>';\n\t}\n rows += '<tr>\\\n <td colspan=\"3\"><hr></td>\\\n </tr>\\\n <tr>\\\n <td colspan=\"2\" align=\"right\">Net Total</td>\\\n <td align=\"right\">' + format_currency(doc.net_total_export) + '</td>\\\n </tr>';\n var taxes = wn.model.get_children(\"Sales Taxes and Charges\", doc.name, \"other_charges\", \"Sales Invoice\");\n if (doc.other_charges_total_export != 0) {\n\t\t$.each(taxes, function(i, d) {\n\t\t\trows += '<tr>\\\n \t\t\t\t<td colspan=\"2\" align=\"right\">' + d.description + '</td>\\\n \t\t\t\t<td style=\"text-align: right;\">' + format_currency(d.tax_amount) + '</td>\\\n \t\t\t<tr>';\n\t\t});\n }\n rows += '<tr>\\\n <td colspan=\"2\" align=\"right\" style=\"vertical-align:middle;\">Grand Total</td>\\\n <td align=\"right\"><hr width=\"90%\" align=\"right\">' + format_currency(doc.grand_total_export) + '<br>\\\n <hr width=\"90%\" align=\"right\"></td>\\\n </tr>\\\n <tr>\\\n <td align=\"center\" colspan=\"3\">Thank You. Please visit again.</td>\\\n </tr>\\\n </table>';\n\treturn rows;\n}\n</script>\n<style>\n table, tr, td, div, p {\n font-family: Monospace;\n line-height: 200%;\n }\n h1, h2, h3, h4, h5, h6 {\n text-align: center;\n }\n\t@media screen {\n\t\tbody {\n\t\t\twidth: 4in;\n\t\t}\n\t}\n</style>\n</head>\n\n<body>\n<table width=\"100%\" cellpadding=\"4\">\n <tr>\n <td align=\"left\">RECEIPT NO: <script>doc.name</script></td>\n <td align=\"right\">DATE: <script>date.str_to_user(doc.posting_date)</script></td>\n </tr>\n <tr>\n <td>M/s <script>doc.customer</script></td>\n </tr>\n</table>\n<!--Item Table & Totals-->\n<div><script>get_print_format();</script></div>\n</body>\n</html>\n",
"module": "Accounts", "module": "Accounts",
"name": "__common__", "name": "__common__",
"print_format_type": "Client", "print_format_type": "Client",

0
patches/1401/__init__.py Normal file
View File

View File

@ -0,0 +1,29 @@
# Copyright (c) 2014, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import webnotes
def execute():
webnotes.reload_doc("stock", "doctype", "price_list")
webnotes.reload_doc("stock", "doctype", "item_price")
if "buying_or_selling" in webnotes.conn.get_table_columns("Price List"):
webnotes.conn.sql("""update `tabPrice List` set
selling =
case
when buying_or_selling='Selling'
then 1
end,
buying =
case
when buying_or_selling='Buying'
then 1
end
""")
webnotes.conn.sql("""update `tabItem Price` ip, `tabPrice List` pl
set ip.buying=pl.buying, ip.selling=pl.selling
where ip.price_list=pl.name""")
webnotes.conn.sql("""udpate `tabItem Price` set selling=1 where ifnull(selling, 0)=0 and
ifnull(buying, 0)=0""")

View File

@ -17,11 +17,8 @@ class DocType:
self.update_item_details() self.update_item_details()
def update_price_list_details(self): def update_price_list_details(self):
if not self.doc.selling and not self.doc.buying: self.doc.buying, self.doc.selling, self.doc.currency = webnotes.conn.get_value("Price List",
self.doc.buying, self.doc.selling = webnotes.conn.get_value("Price List", self.doc.price_list, ["buying", "selling", "currency"])
self.doc.price_list, ["buying", "selling"])
self.doc.currency = webnotes.conn.get_value("Price List", self.doc.price_list, "currency")
def update_item_details(self): def update_item_details(self):
self.doc.item_name, self.doc.item_description = webnotes.conn.get_value("Item", self.doc.item_name, self.doc.item_description = webnotes.conn.get_value("Item",

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-05-02 16:29:48", "creation": "2013-05-02 16:29:48",
"docstatus": 0, "docstatus": 0,
"modified": "2014-01-07 18:11:10", "modified": "2014-01-07 19:16:49",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -64,14 +64,16 @@
"fieldname": "buying", "fieldname": "buying",
"fieldtype": "Check", "fieldtype": "Check",
"in_list_view": 1, "in_list_view": 1,
"label": "Buying" "label": "Buying",
"read_only": 1
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "selling", "fieldname": "selling",
"fieldtype": "Check", "fieldtype": "Check",
"in_list_view": 1, "in_list_view": 1,
"label": "Selling" "label": "Selling",
"read_only": 1
}, },
{ {
"doctype": "DocField", "doctype": "DocField",

View File

@ -4,14 +4,14 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes import msgprint, _, throw from webnotes import msgprint, _, throw
from webnotes.utils import comma_or, cint from webnotes.utils import cint
from webnotes.model.controller import DocListController from webnotes.model.controller import DocListController
import webnotes.defaults import webnotes.defaults
class DocType(DocListController): class DocType(DocListController):
def validate(self): def validate(self):
if not self.doc.buying and not self.doc.selling: if not cint(self.doc.buying) and not cint(self.doc.selling):
throw(_("Price List must be one of Buying or Selling")) throw(_("Price List must be applicable for Buying or Selling"))
if not self.doclist.get({"parentfield": "valid_for_territories"}): if not self.doclist.get({"parentfield": "valid_for_territories"}):
# if no territory, set default territory # if no territory, set default territory
@ -24,24 +24,24 @@ class DocType(DocListController):
else: else:
# at least one territory # at least one territory
self.validate_table_has_rows("valid_for_territories") self.validate_table_has_rows("valid_for_territories")
def on_update(self): def on_update(self):
self.set_default_if_missing() self.set_default_if_missing()
self.update_item_price() self.update_item_price()
cart_settings = webnotes.get_obj("Shopping Cart Settings") cart_settings = webnotes.get_obj("Shopping Cart Settings")
if cint(cart_settings.doc.enabled): if cint(cart_settings.doc.enabled):
cart_settings.validate_price_lists() cart_settings.validate_price_lists()
def set_default_if_missing(self): def set_default_if_missing(self):
if self.doc.selling: if cint(self.doc.selling):
if not webnotes.conn.get_value("Selling Settings", None, "selling_price_list"): if not webnotes.conn.get_value("Selling Settings", None, "selling_price_list"):
webnotes.set_value("Selling Settings", "Selling Settings", "selling_price_list", self.doc.name) webnotes.set_value("Selling Settings", "Selling Settings", "selling_price_list", self.doc.name)
elif self.doc.buying: elif cint(self.doc.buying):
if not webnotes.conn.get_value("Buying Settings", None, "buying_price_list"): if not webnotes.conn.get_value("Buying Settings", None, "buying_price_list"):
webnotes.set_value("Buying Settings", "Buying Settings", "buying_price_list", self.doc.name) webnotes.set_value("Buying Settings", "Buying Settings", "buying_price_list", self.doc.name)
def update_item_price(self): def update_item_price(self):
webnotes.conn.sql("""update `tabItem Price` set currency=%s, webnotes.conn.sql("""update `tabItem Price` set currency=%s,
buying=%s, selling=%s, modified=NOW() where price_list=%s""", buying=%s, selling=%s, modified=NOW() where price_list=%s""",
(self.doc.currency, self.doc.buying, self.doc.selling, self.doc.name)) (self.doc.currency, cint(self.doc.buying), cint(self.doc.selling), self.doc.name))

View File

@ -0,0 +1,22 @@
[
{
"creation": "2013-09-25 10:21:15",
"docstatus": 0,
"modified": "2014-01-07 18:35:22",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"json": "{\"filters\":[[\"Item Price\",\"price_list\",\"like\",\"%\"],[\"Item Price\",\"item_code\",\"like\",\"%\"]],\"columns\":[[\"name\",\"Item Price\"],[\"price_list\",\"Item Price\"],[\"item_code\",\"Item Price\"],[\"item_name\",\"Item Price\"],[\"item_description\",\"Item Price\"],[\"ref_rate\",\"Item Price\"],[\"buying\",\"Item Price\"],[\"selling\",\"Item Price\"],[\"currency\",\"Item Price\"]],\"sort_by\":\"Item Price.modified\",\"sort_order\":\"desc\",\"sort_by_next\":\"\",\"sort_order_next\":\"desc\"}",
"name": "__common__",
"ref_doctype": "Price List",
"report_name": "Item-wise Price List Rate",
"report_type": "Report Builder"
},
{
"doctype": "Report",
"name": "Item-wise Price List Rate"
}
]