Merge lp:~camptocamp/new-report-intrastat/report_intrastat_product_5_group_errors into lp:new-report-intrastat/5.0
- report_intrastat_product_5_group_errors
- Merge into 5.0
Status: | Needs review |
---|---|
Proposed branch: | lp:~camptocamp/new-report-intrastat/report_intrastat_product_5_group_errors |
Merge into: | lp:new-report-intrastat/5.0 |
Diff against target: |
256 lines (+50/-36) 1 file modified
l10n_fr_intrastat_product/intrastat_product.py (+50/-36) |
To merge this branch: | bzr merge lp:~camptocamp/new-report-intrastat/report_intrastat_product_5_group_errors |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexis de Lattre | Pending | ||
Review via email: mp+97183@code.launchpad.net |
Commit message
Description of the change
Hi Alexis,
I propose you a little improvement on your intrastat module for products.
Currently, when you generate lines from invoice or packing, on the first detected error (as example weight net is missing), it stops the generation. You have to fix your product and launch again the generation, which may stop again and so on.
So in this patch whenever we have an error, I put it in a list which is displayed in the error message at the end of the generation. That's a gain if time when you have many many errors.
I you agree with that, I hope I can do the same for the trunk version soon.
Thanks
See you
Unmerged revisions
- 46. By Guewen Baconnier @ Camptocamp <email address hidden>
-
[IMP] instead of raising an errors once they appears, concatenate a list with all errors and raise at the end, this allows to correct them without launching the report generation each time an error is fixed
Preview Diff
1 | === modified file 'l10n_fr_intrastat_product/intrastat_product.py' |
2 | --- l10n_fr_intrastat_product/intrastat_product.py 2011-09-07 16:06:51 +0000 |
3 | +++ l10n_fr_intrastat_product/intrastat_product.py 2012-03-13 10:43:29 +0000 |
4 | @@ -133,6 +133,8 @@ |
5 | if len(ids) != 1: raise osv.except_osv(_('Error :'), 'Hara kiri in build_intrastat_product_line') |
6 | line_obj = self.pool.get('report.intrastat.product.line') |
7 | |
8 | + errors = [] |
9 | + |
10 | if parent_obj._name == 'account.invoice': |
11 | src = 'invoice' |
12 | browse_on = parent_obj.invoice_line |
13 | @@ -199,19 +201,24 @@ |
14 | amount_invoice_currency_to_write = False |
15 | unit_stat_price = self.pool.get('product.pricelist').price_get(cr, uid, [intrastat.company_id.statistical_pricelist_id.id], line.product_id.id, 1.0)[intrastat.company_id.statistical_pricelist_id.id] |
16 | if not unit_stat_price: |
17 | - raise osv.except_osv(_('Error :'), _("The Pricelist for statistical value '%s' that is set for the company '%s' gives a price of 0 for the product '%s'.") %(intrastat.company_id.statistical_pricelist_id.name, intrastat.company_id.name, line.product_id.name)) |
18 | + errors.append(_("The Pricelist for statistical value '%s' that is set for the company '%s' gives a price of 0 for the product '%s'.") % (intrastat.company_id.statistical_pricelist_id.name, intrastat.company_id.name, line.product_id.name)) |
19 | else: |
20 | amount_company_currency_to_write = unit_stat_price * line_qty |
21 | - #print "amount_company_currency_to_write =", amount_company_currency_to_write |
22 | |
23 | + weight_to_write = False |
24 | + source_uom_id_to_write = False |
25 | + intrastat_code_id_to_write = False |
26 | + intrastat_code_to_write = False |
27 | + intrastat_uom_id_to_write = False |
28 | + product_country_origin_id_to_write = False |
29 | if not parent_values['is_fiscal_only']: |
30 | if not line.product_id.weight_net: |
31 | - raise osv.except_osv(_('Error :'), _("Missing net weight on product '%s'.") %(line.product_id.name)) |
32 | + errors.append(_("Missing net weight on product '%s' (%s).") % (line.product_id.name, line.product_id.code)) |
33 | else: |
34 | weight_to_write = line.product_id.weight_net * line_qty |
35 | |
36 | if not source_uom: |
37 | - raise osv.except_osv(_('Error :'), _("Missing unit of measure on the line with %d product(s) '%s' on %s '%s'.") %(line_qty, line.product_id.name, src, parent_name)) |
38 | + errors.append(_("Missing unit of measure on the line with %d product(s) '%s' on %s '%s'.") %(line_qty, line.product_id.name, src, parent_name)) |
39 | else: |
40 | source_uom_id_to_write = source_uom.id |
41 | |
42 | @@ -221,11 +228,11 @@ |
43 | # on it's related category |
44 | product_intrastat_code = line.product_id.categ_id.intrastat_id |
45 | if not product_intrastat_code: |
46 | - raise osv.except_osv(_('Error :'), _("Missing H.S. code on product '%s' or on it's related category '%s'.") %(line.product_id.name, line.product_id.categ_id.complete_name)) |
47 | + errors.append(_("Missing H.S. code on product '%s' or on it's related category '%s'.") %(line.product_id.name, line.product_id.categ_id.complete_name)) |
48 | intrastat_code_id_to_write = product_intrastat_code.id |
49 | |
50 | if not product_intrastat_code.intrastat_code: |
51 | - raise osv.except_osv(_('Error :'), _("Missing intrastat code on H.S. code '%s' (%s).") %(product_intrastat_code.name, product_intrastat_code.description)) |
52 | + errors.append(_("Missing intrastat code on H.S. code '%s' (%s).") %(product_intrastat_code.name, product_intrastat_code.description)) |
53 | else: |
54 | intrastat_code_to_write = product_intrastat_code.intrastat_code |
55 | |
56 | @@ -235,24 +242,16 @@ |
57 | intrastat_uom_id_to_write = product_intrastat_code.intrastat_uom_id.id |
58 | |
59 | if intrastat_uom_id_to_write and intrastat_uom_id_to_write != source_uom_id_to_write: |
60 | - raise osv.except_osv(_('Error :'), _("On %s '%s', the line with %d product(s) '%s' has a unit of measure (%s) which is different from the UoM of it's intrastat code (%s). We don't handle this scenario for the moment.") %(src, parent_name, line_qty, line.product_id.name, source_uom_id_to_write, intrastat_uom_id_to_write)) |
61 | + errors.append(_("On %s '%s', the line with %d product(s) '%s' has a unit of measure (%s) which is different from the UoM of it's intrastat code (%s). We don't handle this scenario for the moment.") %(src, parent_name, line_qty, line.product_id.name, source_uom_id_to_write, intrastat_uom_id_to_write)) |
62 | |
63 | # The origin country should only be declated on Import |
64 | if intrastat.type == 'export': |
65 | product_country_origin_id_to_write = False |
66 | elif not line.product_id.country_id: |
67 | - raise osv.except_osv(_('Error :'), _("Missing country of origin on product '%s'.") %(line.product_id.name)) |
68 | + errors.append(_("Missing country of origin on product '%s'.") % line.product_id.name) |
69 | else: |
70 | product_country_origin_id_to_write = line.product_id.country_id.id |
71 | |
72 | - else: |
73 | - weight_to_write = False |
74 | - source_uom_id_to_write = False |
75 | - intrastat_code_id_to_write = False |
76 | - intrastat_code_to_write = False |
77 | - intrastat_uom_id_to_write = False |
78 | - product_country_origin_id_to_write = False |
79 | - |
80 | create_new_line = True |
81 | #print "lines_to_create =", lines_to_create |
82 | for line_to_create in lines_to_create: |
83 | @@ -298,27 +297,31 @@ |
84 | # will be skipped because line_tax.exclude_from_intrastat_if_present is always True |
85 | # So we should not block with a raise before the end of the loop on the |
86 | # invoice/picking lines |
87 | + |
88 | if lines_to_create: |
89 | if parent_values['is_vat_required']: |
90 | if src <> 'invoice': |
91 | - raise osv.except_osv(_('Error :'), "We can't have such an intrastat type in a repair picking.") |
92 | + errors.append("We can't have such an intrastat type in a repair picking.") |
93 | # If I have invoice.intrastat_country_id and the invoice address |
94 | # is outside the EU, then I look for the fiscal rep of the partner |
95 | if parent_obj.intrastat_country_id and not parent_obj.address_invoice_id.country_id.intrastat: |
96 | if not parent_obj.partner_id.intrastat_fiscal_representative: |
97 | - raise osv.except_osv(_('Error :'), _("Missing fiscal representative for partner '%s'. It is required for invoice '%s' which has an invoice address outside the EU but the goods were delivered to or received from inside the EU.") % (parent_obj.partner_id.name, parent_obj.number)) |
98 | + errors.append(_("Missing fiscal representative for partner '%s'. It is required for invoice '%s' which has an invoice address outside the EU but the goods were delivered to or received from inside the EU.") % (parent_obj.partner_id.name, parent_obj.number)) |
99 | else: |
100 | parent_values['partner_vat_to_write'] = parent_obj.partner_id.intrastat_fiscal_representative.vat |
101 | # Otherwise, I just read the vat number on the partner of the invoice |
102 | else: |
103 | |
104 | if not parent_obj.partner_id.vat: |
105 | - raise osv.except_osv(_('Error :'), _("Missing VAT number on partner '%s'.") %parent_obj.partner_id.name) |
106 | + errors.append(_("Missing VAT number on partner '%s'.") % parent_obj.partner_id.name) |
107 | else: |
108 | parent_values['partner_vat_to_write'] = parent_obj.partner_id.vat |
109 | else: |
110 | parent_values['partner_vat_to_write'] = False |
111 | |
112 | + if errors: |
113 | + return False, errors |
114 | + |
115 | for line_to_create in lines_to_create: |
116 | line_to_create['partner_vat'] = parent_values['partner_vat_to_write'] |
117 | for value in ['quantity', 'weight', 'amount_company_currency', 'amount_invoice_currency']: |
118 | @@ -326,7 +329,7 @@ |
119 | line_to_create[value] = str(int(round(line_to_create[value], 0))) |
120 | line_obj.create(cr, uid, line_to_create, context=context) |
121 | |
122 | - return True |
123 | + return True, [] |
124 | |
125 | |
126 | def common_compute_invoice_picking(self, cr, uid, intrastat, parent_obj, parent_values, context=None): |
127 | @@ -349,6 +352,10 @@ |
128 | parent_name = parent_obj.name |
129 | else: raise osv.except_osv(_('Error :'), 'The function build_intrastat_product_lines() should have parent_obj as invoice or picking') |
130 | |
131 | + parent_values['department_to_write'] = False |
132 | + parent_values['transport_to_write'] = False |
133 | + parent_values['transaction_code_to_write'] = False |
134 | + parent_values['partner_country_id_to_write'] = False |
135 | if not parent_values['is_fiscal_only']: |
136 | if not parent_obj.intrastat_transport: |
137 | try: parent_values['transport_to_write'] = intrastat.company_id.default_intrastat_transport |
138 | @@ -361,11 +368,6 @@ |
139 | except: raise osv.except_osv(_('Error :'), _("The intrastat department hasn't been set on %s '%s' and the default intrastat department is missing on the company '%s'.") %(src, parent_name, intrastat.company_id.name)) |
140 | else: |
141 | parent_values['department_to_write'] = parent_obj.intrastat_department |
142 | - else: |
143 | - parent_values['department_to_write'] = False |
144 | - parent_values['transport_to_write'] = False |
145 | - parent_values['transaction_code_to_write'] = False |
146 | - parent_values['partner_country_id_to_write'] = False |
147 | |
148 | return parent_values |
149 | |
150 | @@ -402,13 +404,14 @@ |
151 | ('company_id', '=', intrastat.company_id.id) |
152 | ], order='date_invoice', context=context) |
153 | #print "invoice_ids=", invoice_ids |
154 | + errors = [] |
155 | for invoice in invoice_obj.browse(cr, uid, invoice_ids, context=context): |
156 | #print "INVOICE num =", invoice.number |
157 | parent_values = {} |
158 | |
159 | # We should always have a country on address_invoice_id |
160 | if not invoice.address_invoice_id.country_id: |
161 | - raise osv.except_osv(_('Error :'), _("Missing country on partner address '%s' of partner '%s'.") %(invoice.address_invoice_id.name, invoice.address_invoice_id.partner_id.name)) |
162 | + errors.append(_("Missing country on partner address '%s' of partner '%s'.") % (invoice.address_invoice_id.name, invoice.address_invoice_id.partner_id.name)) |
163 | |
164 | # If I have no invoice.intrastat_country_id, which is the case the first month |
165 | # of the deployment of the module, then I use the country on invoice address |
166 | @@ -430,17 +433,17 @@ |
167 | if intrastat.company_id.default_intrastat_type_out_invoice: |
168 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_invoice.id |
169 | else: |
170 | - raise osv.except_osv(_('Error :'), _("The intrastat type hasn't been set on invoice '%s' and the 'default intrastat type for customer invoice' is missing for the company '%s'.") %(invoice.number, intrastat.company_id.name)) |
171 | + errors.append(_("The intrastat type hasn't been set on invoice '%s' and the 'default intrastat type for customer invoice' is missing for the company '%s'.") %(invoice.number, intrastat.company_id.name)) |
172 | elif invoice.type == 'out_refund': |
173 | if intrastat.company_id.default_intrastat_type_out_refund: |
174 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_refund.id |
175 | else: |
176 | - raise osv.except_osv(_('Error :'), _("The intrastat type hasn't been set on refund '%s' and the 'default intrastat type for customer refund' is missing for the company '%s'.") %(invoice.number, intrastat.company_id.name)) |
177 | + errors.append(_("The intrastat type hasn't been set on refund '%s' and the 'default intrastat type for customer refund' is missing for the company '%s'.") %(invoice.number, intrastat.company_id.name)) |
178 | elif invoice.type == 'in_invoice': |
179 | if intrastat.company_id.default_intrastat_type_in_invoice: |
180 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_in_invoice.id |
181 | else: |
182 | - raise osv.except_osv(_('Error :'), _("The intrastat type hasn't been set on invoice '%s' and the 'Default intrastat type for supplier invoice' is missing for the company '%s'.") %(invoice.number, intrastat.company_id.name)) |
183 | + errors.append(_("The intrastat type hasn't been set on invoice '%s' and the 'Default intrastat type for supplier invoice' is missing for the company '%s'.") %(invoice.number, intrastat.company_id.name)) |
184 | else: raise osv.except_osv(_('Error :'), "Hara kiri... we can't have a supplier refund") |
185 | |
186 | else: |
187 | @@ -454,7 +457,12 @@ |
188 | |
189 | parent_values = self.common_compute_invoice_picking(cr, uid, intrastat, invoice, parent_values, context=context) |
190 | |
191 | - self.create_intrastat_product_lines(cr, uid, ids, intrastat, invoice, parent_values, context=context) |
192 | + __, product_errors = self.create_intrastat_product_lines(cr, uid, ids, intrastat, invoice, parent_values, context=context) |
193 | + if product_errors: |
194 | + errors += product_errors |
195 | + |
196 | + if errors: |
197 | + raise osv.except_osv(_('Errors'), '\n'.join(errors)) |
198 | |
199 | return True |
200 | |
201 | @@ -496,7 +504,8 @@ |
202 | (exclude_field, '=', False), |
203 | ('state', 'not in', ('draft', 'waiting', 'confirmed', 'assigned', 'cancel')) |
204 | ], order='date_done', context=context) |
205 | - #print "picking_ids =", picking_ids |
206 | + |
207 | + errors = [] |
208 | for picking in pick_obj.browse(cr, uid, picking_ids, context=context): |
209 | parent_values = {} |
210 | #print "PICKING =", picking.name |
211 | @@ -504,7 +513,7 @@ |
212 | continue |
213 | |
214 | if not picking.address_id.country_id: |
215 | - raise osv.except_osv(_('Error :'), _("Missing country on partner address '%s' used on picking '%s'.") %(picking.address_id.name, picking.name)) |
216 | + errors.append(_("Missing country on partner address '%s' used on picking '%s'.") % (picking.address_id.name, picking.name)) |
217 | elif not picking.address_id.country_id.intrastat: |
218 | continue |
219 | else: |
220 | @@ -512,7 +521,7 @@ |
221 | |
222 | |
223 | if not picking.address_id.partner_id: |
224 | - raise osv.except_osv(_('Error :'), _("Partner address '%s' used on picking '%s' is not linked to a partner !") %(move_line.address_id.name, picking.name)) |
225 | + errors.append(_("Partner address '%s' used on picking '%s' is not linked to a partner !") % (picking.address_id.name, picking.name)) |
226 | else: |
227 | parent_values['partner_id_to_write'] = picking.address_id.partner_id.id |
228 | |
229 | @@ -522,12 +531,12 @@ |
230 | if intrastat.company_id.default_intrastat_type_out_picking: |
231 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_picking.id |
232 | else: |
233 | - raise osv.except_osv(_('Error :'), _("The intrastat type hasn't been set on picking '%s' and the 'default intrastat type for outgoing products' is missing for the company '%s'.") %(picking.name, intrastat.company_id.name)) |
234 | + errors.append(_("The intrastat type hasn't been set on picking '%s' and the 'default intrastat type for outgoing products' is missing for the company '%s'.") % (picking.name, intrastat.company_id.name)) |
235 | elif picking.type == 'in': |
236 | if intrastat.company_id.default_intrastat_type_in_picking: |
237 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_in_picking.id |
238 | else: |
239 | - raise osv.except_osv(_('Error :'), _("The intrastat type hasn't been set on picking '%s' and the 'default intrastat type for incoming products' is missing for the company '%s'.") %(picking.name, intrastat.company_id.name)) |
240 | + errors.append(_("The intrastat type hasn't been set on picking '%s' and the 'default intrastat type for incoming products' is missing for the company '%s'.") % (picking.name, intrastat.company_id.name)) |
241 | else: raise osv.except_osv(_('Error :'), "Hara kiri... we can't arrive here") |
242 | else: |
243 | parent_values['intrastat_type_id_to_write'] = picking.intrastat_type_id.id |
244 | @@ -535,7 +544,12 @@ |
245 | |
246 | parent_values = self.common_compute_invoice_picking(cr, uid, intrastat, picking, parent_values, context=context) |
247 | |
248 | - self.create_intrastat_product_lines(cr, uid, ids, intrastat, picking, parent_values, context=context) |
249 | + __, product_errors = self.create_intrastat_product_lines(cr, uid, ids, intrastat, picking, parent_values, context=context) |
250 | + if product_errors: |
251 | + errors += product_errors |
252 | + |
253 | + if errors: |
254 | + raise osv.except_osv(_('Errors'), '\n'.join(errors)) |
255 | |
256 | return True |
257 |