Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 1 | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. |
| 2 | # License: GNU General Public License v3. See license.txt |
Nabin Hait | ec52db8 | 2013-01-22 11:53:14 +0530 | [diff] [blame] | 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | import webnotes |
Nabin Hait | 040d1f3 | 2013-08-21 17:04:33 +0530 | [diff] [blame] | 6 | from webnotes.utils import cint, flt, comma_or, _round, add_days, cstr |
Nabin Hait | ec52db8 | 2013-01-22 11:53:14 +0530 | [diff] [blame] | 7 | from setup.utils import get_company_currency |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 8 | from selling.utils import get_item_details |
Nabin Hait | 0fc2454 | 2013-03-25 11:06:00 +0530 | [diff] [blame] | 9 | from webnotes import msgprint, _ |
Nabin Hait | ec52db8 | 2013-01-22 11:53:14 +0530 | [diff] [blame] | 10 | |
Nabin Hait | c3afb25 | 2013-03-19 12:01:24 +0530 | [diff] [blame] | 11 | from controllers.stock_controller import StockController |
Nabin Hait | bf495c9 | 2013-01-30 12:49:08 +0530 | [diff] [blame] | 12 | |
Nabin Hait | c3afb25 | 2013-03-19 12:01:24 +0530 | [diff] [blame] | 13 | class SellingController(StockController): |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 14 | def onload_post_render(self): |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 15 | # contact, address, item details and pos details (if applicable) |
| 16 | self.set_missing_values() |
Nabin Hait | a9ec49e | 2013-07-15 16:33:24 +0530 | [diff] [blame] | 17 | |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 18 | def set_missing_values(self, for_validate=False): |
Anand Doshi | abc1003 | 2013-06-14 17:44:03 +0530 | [diff] [blame] | 19 | super(SellingController, self).set_missing_values(for_validate) |
| 20 | |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 21 | # set contact and address details for customer, if they are not mentioned |
Anand Doshi | abc1003 | 2013-06-14 17:44:03 +0530 | [diff] [blame] | 22 | self.set_missing_lead_customer_details() |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 23 | self.set_price_list_and_item_details() |
Rushabh Mehta | e89c533 | 2013-08-29 15:32:46 +0530 | [diff] [blame] | 24 | if self.doc.fields.get("__islocal"): |
| 25 | self.set_taxes("other_charges", "charge") |
Anand Doshi | abc1003 | 2013-06-14 17:44:03 +0530 | [diff] [blame] | 26 | |
| 27 | def set_missing_lead_customer_details(self): |
| 28 | if self.doc.customer: |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 29 | if not (self.doc.contact_person and self.doc.customer_address and self.doc.customer_name): |
| 30 | for fieldname, val in self.get_customer_defaults().items(): |
Anand Doshi | abc1003 | 2013-06-14 17:44:03 +0530 | [diff] [blame] | 31 | if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname): |
| 32 | self.doc.fields[fieldname] = val |
| 33 | |
Anand Doshi | abc1003 | 2013-06-14 17:44:03 +0530 | [diff] [blame] | 34 | elif self.doc.lead: |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 35 | if not (self.doc.customer_address and self.doc.customer_name and \ |
| 36 | self.doc.contact_display): |
| 37 | for fieldname, val in self.get_lead_defaults().items(): |
| 38 | if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname): |
| 39 | self.doc.fields[fieldname] = val |
| 40 | |
| 41 | def set_price_list_and_item_details(self): |
| 42 | self.set_price_list_currency("Selling") |
| 43 | self.set_missing_item_details(get_item_details) |
Nabin Hait | 2bd3777 | 2013-07-08 19:00:29 +0530 | [diff] [blame] | 44 | |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 45 | def get_other_charges(self): |
| 46 | self.doclist = self.doc.clear_table(self.doclist, "other_charges") |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 47 | self.set_taxes("other_charges", "charge") |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 48 | |
Anand Doshi | 99100a4 | 2013-07-04 17:13:53 +0530 | [diff] [blame] | 49 | def apply_shipping_rule(self): |
| 50 | if self.doc.shipping_rule: |
| 51 | shipping_rule = webnotes.bean("Shipping Rule", self.doc.shipping_rule) |
| 52 | value = self.doc.net_total |
| 53 | |
| 54 | # TODO |
| 55 | # shipping rule calculation based on item's net weight |
| 56 | |
| 57 | shipping_amount = 0.0 |
| 58 | for condition in shipping_rule.doclist.get({"parentfield": "shipping_rule_conditions"}): |
| 59 | if not condition.to_value or (flt(condition.from_value) <= value <= flt(condition.to_value)): |
| 60 | shipping_amount = condition.shipping_amount |
| 61 | break |
Anand Doshi | 0b4943c | 2013-07-04 23:45:22 +0530 | [diff] [blame] | 62 | |
| 63 | self.doclist.append({ |
| 64 | "doctype": "Sales Taxes and Charges", |
| 65 | "parentfield": "other_charges", |
| 66 | "charge_type": "Actual", |
| 67 | "account_head": shipping_rule.doc.account, |
| 68 | "cost_center": shipping_rule.doc.cost_center, |
| 69 | "description": shipping_rule.doc.label, |
| 70 | "rate": shipping_amount |
| 71 | }) |
Anand Doshi | fc77718 | 2013-05-27 19:29:07 +0530 | [diff] [blame] | 72 | |
Nabin Hait | ec52db8 | 2013-01-22 11:53:14 +0530 | [diff] [blame] | 73 | def set_total_in_words(self): |
| 74 | from webnotes.utils import money_in_words |
| 75 | company_currency = get_company_currency(self.doc.company) |
Nabin Hait | 6f1a5ec | 2013-02-20 16:25:05 +0530 | [diff] [blame] | 76 | |
| 77 | disable_rounded_total = cint(webnotes.conn.get_value("Global Defaults", None, |
| 78 | "disable_rounded_total")) |
| 79 | |
Nabin Hait | ec52db8 | 2013-01-22 11:53:14 +0530 | [diff] [blame] | 80 | if self.meta.get_field("in_words"): |
Nabin Hait | 6f1a5ec | 2013-02-20 16:25:05 +0530 | [diff] [blame] | 81 | self.doc.in_words = money_in_words(disable_rounded_total and |
| 82 | self.doc.grand_total or self.doc.rounded_total, company_currency) |
Nabin Hait | ec52db8 | 2013-01-22 11:53:14 +0530 | [diff] [blame] | 83 | if self.meta.get_field("in_words_export"): |
Nabin Hait | 6f1a5ec | 2013-02-20 16:25:05 +0530 | [diff] [blame] | 84 | self.doc.in_words_export = money_in_words(disable_rounded_total and |
Nabin Hait | 8c7234f | 2013-03-11 16:32:33 +0530 | [diff] [blame] | 85 | self.doc.grand_total_export or self.doc.rounded_total_export, self.doc.currency) |
Nabin Hait | a0e7c15 | 2013-03-21 18:37:06 +0530 | [diff] [blame] | 86 | |
Nabin Hait | 787c02e | 2013-03-29 16:42:33 +0530 | [diff] [blame] | 87 | def set_buying_amount(self, stock_ledger_entries = None): |
Nabin Hait | 94c90bd | 2013-08-30 22:48:19 +0530 | [diff] [blame] | 88 | from stock.utils import get_buying_amount, get_sales_bom_buying_amount |
Nabin Hait | 787c02e | 2013-03-29 16:42:33 +0530 | [diff] [blame] | 89 | if not stock_ledger_entries: |
| 90 | stock_ledger_entries = self.get_stock_ledger_entries() |
Anand Doshi | 8c5844e | 2013-03-21 20:24:10 +0530 | [diff] [blame] | 91 | |
| 92 | item_sales_bom = {} |
| 93 | for d in self.doclist.get({"parentfield": "packing_details"}): |
| 94 | new_d = webnotes._dict(d.fields.copy()) |
| 95 | new_d.total_qty = -1 * d.qty |
| 96 | item_sales_bom.setdefault(d.parent_item, []).append(new_d) |
Nabin Hait | a0e7c15 | 2013-03-21 18:37:06 +0530 | [diff] [blame] | 97 | |
| 98 | if stock_ledger_entries: |
| 99 | for item in self.doclist.get({"parentfield": self.fname}): |
| 100 | if item.item_code in self.stock_items or \ |
| 101 | (item_sales_bom and item_sales_bom.get(item.item_code)): |
Anand Doshi | 215c901 | 2013-09-02 15:38:53 +0530 | [diff] [blame] | 102 | |
| 103 | buying_amount = 0 |
Nabin Hait | 94c90bd | 2013-08-30 22:48:19 +0530 | [diff] [blame] | 104 | if item.item_code in self.stock_items: |
| 105 | buying_amount = get_buying_amount(self.doc.doctype, self.doc.name, |
| 106 | item.name, stock_ledger_entries.get((item.item_code, |
| 107 | item.warehouse), [])) |
| 108 | elif item_sales_bom and item_sales_bom.get(item.item_code): |
| 109 | buying_amount = get_sales_bom_buying_amount(item.item_code, item.warehouse, |
| 110 | self.doc.doctype, self.doc.name, item.name, stock_ledger_entries, |
| 111 | item_sales_bom) |
Nabin Hait | f2d4df9 | 2013-05-07 13:12:02 +0530 | [diff] [blame] | 112 | |
Anand Doshi | 215c901 | 2013-09-02 15:38:53 +0530 | [diff] [blame] | 113 | # buying_amount >= 0.01 so that gl entry doesn't get created for such small amounts |
| 114 | item.buying_amount = buying_amount >= 0.01 and buying_amount or 0 |
| 115 | webnotes.conn.set_value(item.doctype, item.name, "buying_amount", |
| 116 | item.buying_amount) |
Nabin Hait | 0fc2454 | 2013-03-25 11:06:00 +0530 | [diff] [blame] | 117 | |
| 118 | def check_expense_account(self, item): |
| 119 | if item.buying_amount and not item.expense_account: |
| 120 | msgprint(_("""Expense account is mandatory for item: """) + item.item_code, |
Nabin Hait | 787c02e | 2013-03-29 16:42:33 +0530 | [diff] [blame] | 121 | raise_exception=1) |
| 122 | |
| 123 | if item.buying_amount and not item.cost_center: |
| 124 | msgprint(_("""Cost Center is mandatory for item: """) + item.item_code, |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 125 | raise_exception=1) |
| 126 | |
| 127 | def calculate_taxes_and_totals(self): |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 128 | self.other_fname = "other_charges" |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 129 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 130 | super(SellingController, self).calculate_taxes_and_totals() |
| 131 | |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 132 | self.calculate_total_advance("Sales Invoice", "advance_adjustment_details") |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 133 | self.calculate_commission() |
| 134 | self.calculate_contribution() |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 135 | |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 136 | def determine_exclusive_rate(self): |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 137 | if not any((cint(tax.included_in_print_rate) for tax in self.tax_doclist)): |
| 138 | # no inclusive tax |
| 139 | return |
| 140 | |
| 141 | for item in self.item_doclist: |
| 142 | item_tax_map = self._load_item_tax_rate(item.item_tax_rate) |
| 143 | cumulated_tax_fraction = 0 |
| 144 | for i, tax in enumerate(self.tax_doclist): |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 145 | tax.tax_fraction_for_current_item = self.get_current_tax_fraction(tax, item_tax_map) |
| 146 | |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 147 | if i==0: |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 148 | tax.grand_total_fraction_for_current_item = 1 + tax.tax_fraction_for_current_item |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 149 | else: |
| 150 | tax.grand_total_fraction_for_current_item = \ |
| 151 | self.tax_doclist[i-1].grand_total_fraction_for_current_item \ |
| 152 | + tax.tax_fraction_for_current_item |
| 153 | |
| 154 | cumulated_tax_fraction += tax.tax_fraction_for_current_item |
| 155 | |
| 156 | if cumulated_tax_fraction: |
Anand Doshi | fbe1e16 | 2013-08-06 19:38:19 +0530 | [diff] [blame] | 157 | item.amount = flt((item.export_amount * self.doc.conversion_rate) / |
| 158 | (1 + cumulated_tax_fraction), self.precision("amount", item)) |
| 159 | |
| 160 | item.basic_rate = flt(item.amount / item.qty, self.precision("basic_rate", item)) |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 161 | |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 162 | if item.adj_rate == 100: |
| 163 | item.base_ref_rate = item.basic_rate |
| 164 | item.basic_rate = 0.0 |
| 165 | else: |
| 166 | item.base_ref_rate = flt(item.basic_rate / (1 - (item.adj_rate / 100.0)), |
| 167 | self.precision("base_ref_rate", item)) |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 168 | |
| 169 | def get_current_tax_fraction(self, tax, item_tax_map): |
| 170 | """ |
| 171 | Get tax fraction for calculating tax exclusive amount |
| 172 | from tax inclusive amount |
| 173 | """ |
| 174 | current_tax_fraction = 0 |
| 175 | |
| 176 | if cint(tax.included_in_print_rate): |
| 177 | tax_rate = self._get_tax_rate(tax, item_tax_map) |
| 178 | |
| 179 | if tax.charge_type == "On Net Total": |
| 180 | current_tax_fraction = tax_rate / 100.0 |
| 181 | |
| 182 | elif tax.charge_type == "On Previous Row Amount": |
| 183 | current_tax_fraction = (tax_rate / 100.0) * \ |
| 184 | self.tax_doclist[cint(tax.row_id) - 1].tax_fraction_for_current_item |
| 185 | |
| 186 | elif tax.charge_type == "On Previous Row Total": |
| 187 | current_tax_fraction = (tax_rate / 100.0) * \ |
| 188 | self.tax_doclist[cint(tax.row_id) - 1].grand_total_fraction_for_current_item |
| 189 | |
| 190 | return current_tax_fraction |
| 191 | |
| 192 | def calculate_item_values(self): |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 193 | for item in self.item_doclist: |
Anand Doshi | 39384d3 | 2013-05-11 19:39:53 +0530 | [diff] [blame] | 194 | self.round_floats_in(item) |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 195 | |
| 196 | if item.adj_rate == 100: |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 197 | item.export_rate = 0 |
Anand Doshi | 47e14a9 | 2013-08-13 13:01:12 +0530 | [diff] [blame] | 198 | elif not item.export_rate: |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 199 | item.export_rate = flt(item.ref_rate * (1.0 - (item.adj_rate / 100.0)), |
| 200 | self.precision("export_rate", item)) |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 201 | |
| 202 | item.export_amount = flt(item.export_rate * item.qty, |
Anand Doshi | 39384d3 | 2013-05-11 19:39:53 +0530 | [diff] [blame] | 203 | self.precision("export_amount", item)) |
Rushabh Mehta | 4dca401 | 2013-07-25 17:45:59 +0530 | [diff] [blame] | 204 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 205 | self._set_in_company_currency(item, "ref_rate", "base_ref_rate") |
| 206 | self._set_in_company_currency(item, "export_rate", "basic_rate") |
| 207 | self._set_in_company_currency(item, "export_amount", "amount") |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 208 | |
| 209 | def calculate_net_total(self): |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 210 | self.doc.net_total = self.doc.net_total_export = 0.0 |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 211 | |
| 212 | for item in self.item_doclist: |
| 213 | self.doc.net_total += item.amount |
| 214 | self.doc.net_total_export += item.export_amount |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 215 | |
| 216 | self.round_floats_in(self.doc, ["net_total", "net_total_export"]) |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 217 | |
| 218 | def calculate_totals(self): |
| 219 | self.doc.grand_total = flt(self.tax_doclist and \ |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 220 | self.tax_doclist[-1].total or self.doc.net_total, self.precision("grand_total")) |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 221 | self.doc.grand_total_export = flt(self.doc.grand_total / self.doc.conversion_rate, |
Anand Doshi | 5af812a | 2013-05-10 19:23:02 +0530 | [diff] [blame] | 222 | self.precision("grand_total_export")) |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 223 | |
| 224 | self.doc.other_charges_total = flt(self.doc.grand_total - self.doc.net_total, |
| 225 | self.precision("other_charges_total")) |
| 226 | self.doc.other_charges_total_export = flt(self.doc.grand_total_export - self.doc.net_total_export, |
| 227 | self.precision("other_charges_total_export")) |
Anand Doshi | 21f4ea3 | 2013-05-10 18:08:32 +0530 | [diff] [blame] | 228 | |
Anand Doshi | 2e31e09 | 2013-08-19 19:58:23 +0530 | [diff] [blame] | 229 | self.doc.rounded_total = _round(self.doc.grand_total) |
| 230 | self.doc.rounded_total_export = _round(self.doc.grand_total_export) |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 231 | |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 232 | def calculate_outstanding_amount(self): |
| 233 | # NOTE: |
| 234 | # write_off_amount is only for POS Invoice |
| 235 | # total_advance is only for non POS Invoice |
| 236 | if self.doc.doctype == "Sales Invoice" and self.doc.docstatus < 2: |
| 237 | self.round_floats_in(self.doc, ["grand_total", "total_advance", "write_off_amount", |
| 238 | "paid_amount"]) |
| 239 | total_amount_to_pay = self.doc.grand_total - self.doc.write_off_amount |
| 240 | self.doc.outstanding_amount = flt(total_amount_to_pay - self.doc.total_advance - self.doc.paid_amount, |
| 241 | self.precision("outstanding_amount")) |
| 242 | |
| 243 | def calculate_commission(self): |
| 244 | if self.meta.get_field("commission_rate"): |
| 245 | self.round_floats_in(self.doc, ["net_total", "commission_rate"]) |
| 246 | if self.doc.commission_rate > 100.0: |
| 247 | msgprint(_(self.meta.get_label("commission_rate")) + " " + |
| 248 | _("cannot be greater than 100"), raise_exception=True) |
| 249 | |
| 250 | self.doc.total_commission = flt(self.doc.net_total * self.doc.commission_rate / 100.0, |
| 251 | self.precision("total_commission")) |
Anand Doshi | f309613 | 2013-05-21 19:35:06 +0530 | [diff] [blame] | 252 | |
| 253 | def calculate_contribution(self): |
| 254 | total = 0.0 |
| 255 | sales_team = self.doclist.get({"parentfield": "sales_team"}) |
| 256 | for sales_person in sales_team: |
| 257 | self.round_floats_in(sales_person) |
| 258 | |
| 259 | sales_person.allocated_amount = flt( |
| 260 | self.doc.net_total * sales_person.allocated_percentage / 100.0, |
| 261 | self.precision("allocated_amount", sales_person)) |
| 262 | |
| 263 | total += sales_person.allocated_percentage |
| 264 | |
| 265 | if sales_team and total != 100.0: |
| 266 | msgprint(_("Total") + " " + |
| 267 | _(self.meta.get_label("allocated_percentage", parentfield="sales_team")) + |
| 268 | " " + _("should be 100%"), raise_exception=True) |
Anand Doshi | 1dde46a | 2013-05-15 21:15:57 +0530 | [diff] [blame] | 269 | |
| 270 | def validate_order_type(self): |
Anand Doshi | abc1003 | 2013-06-14 17:44:03 +0530 | [diff] [blame] | 271 | valid_types = ["Sales", "Maintenance", "Shopping Cart"] |
Rushabh Mehta | 080fcc8 | 2013-07-04 15:27:04 +0530 | [diff] [blame] | 272 | if not self.doc.order_type: |
| 273 | self.doc.order_type = "Sales" |
| 274 | elif self.doc.order_type not in valid_types: |
Anand Doshi | 1dde46a | 2013-05-15 21:15:57 +0530 | [diff] [blame] | 275 | msgprint(_(self.meta.get_label("order_type")) + " " + |
| 276 | _("must be one of") + ": " + comma_or(valid_types), |
| 277 | raise_exception=True) |
Rushabh Mehta | 62030e0 | 2013-08-14 18:37:28 +0530 | [diff] [blame] | 278 | |
| 279 | def update_serial_nos(self, cancel=False): |
| 280 | from stock.doctype.stock_ledger_entry.stock_ledger_entry import update_serial_nos_after_submit, get_serial_nos |
| 281 | update_serial_nos_after_submit(self, self.doc.doctype, self.fname) |
| 282 | update_serial_nos_after_submit(self, self.doc.doctype, "packing_details") |
| 283 | |
| 284 | for table_fieldname in (self.fname, "packing_details"): |
| 285 | for d in self.doclist.get({"parentfield": table_fieldname}): |
| 286 | for serial_no in get_serial_nos(d.serial_no): |
| 287 | sr = webnotes.bean("Serial No", serial_no) |
| 288 | if cancel: |
| 289 | sr.doc.status = "Available" |
| 290 | for fieldname in ("warranty_expiry_date", "delivery_document_type", |
| 291 | "delivery_document_no", "delivery_date", "delivery_time", "customer", |
| 292 | "customer_name"): |
| 293 | sr.doc.fields[fieldname] = None |
| 294 | else: |
| 295 | sr.doc.delivery_document_type = self.doc.doctype |
| 296 | sr.doc.delivery_document_no = self.doc.name |
| 297 | sr.doc.delivery_date = self.doc.posting_date |
| 298 | sr.doc.delivery_time = self.doc.posting_time |
| 299 | sr.doc.customer = self.doc.customer |
| 300 | sr.doc.customer_name = self.doc.customer_name |
| 301 | if sr.doc.warranty_period: |
Nabin Hait | e98ab7a | 2013-08-21 16:56:12 +0530 | [diff] [blame] | 302 | sr.doc.warranty_expiry_date = add_days(cstr(self.doc.posting_date), |
Rushabh Mehta | 62030e0 | 2013-08-14 18:37:28 +0530 | [diff] [blame] | 303 | cint(sr.doc.warranty_period)) |
| 304 | sr.doc.status = 'Delivered' |
| 305 | |
| 306 | sr.save() |