Merge lp:~camptocamp/new-report-intrastat/7.0-post-all-errors-rather-than-one-by-one into lp:new-report-intrastat
- 7.0-post-all-errors-rather-than-one-by-one
- Merge into trunk
Status: | Needs review |
---|---|
Proposed branch: | lp:~camptocamp/new-report-intrastat/7.0-post-all-errors-rather-than-one-by-one |
Merge into: | lp:new-report-intrastat |
Diff against target: |
463 lines (+235/-69) 1 file modified
l10n_fr_intrastat_product/intrastat_product.py (+235/-69) |
To merge this branch: | bzr merge lp:~camptocamp/new-report-intrastat/7.0-post-all-errors-rather-than-one-by-one |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexis de Lattre | Needs Fixing | ||
Review via email: mp+222924@code.launchpad.net |
Commit message
Post a message with all errors rather than raising them one by one.
Description of the change
In l10n_fr_
When:
When we generate DEB lines and several lines have errors (misconfiguration of products, partners, ...).
Current behavior:
The first error is raised so the user must correct it and launch again the generation, and repeat this cycle until all errors are fixed.
Proposal:
Accumulate all the errors and show them in a mail message at the bottom of the view.
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
Sorry for the regression.
I did not changed that for code cleaning. The problem when initializing the keys in the 'else' was that we could have KeyError when they are accessed later, that's why I initialized them before the if.
I will try to find another way to do that.
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
I reverted the change for the keys that were already initialized earlier in the process. I left the initialization of the keys that were never set before.
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
I completely checked when the keys are initialized for the first time and I'm sure that keys are no longer squashed.
- 94. By Guewen Baconnier @ Camptocamp
-
skip the source uom checks when a line has no uom
Unmerged revisions
- 94. By Guewen Baconnier @ Camptocamp
-
skip the source uom checks when a line has no uom
- 93. By Guewen Baconnier @ Camptocamp
-
'partner_
country_ id_to_write' could have been initialized before - 92. By Guewen Baconnier @ Camptocamp
-
do not reset 'transaction_
code_to_ write', it should be False only when is_fiscal_only is true - 91. By Guewen Baconnier @ Camptocamp
-
Post a message with all errors rather than raising them one by one.
Preview Diff
1 | === modified file 'l10n_fr_intrastat_product/intrastat_product.py' | |||
2 | --- l10n_fr_intrastat_product/intrastat_product.py 2014-07-03 22:18:44 +0000 | |||
3 | +++ l10n_fr_intrastat_product/intrastat_product.py 2014-08-12 13:38:07 +0000 | |||
4 | @@ -20,8 +20,10 @@ | |||
5 | 20 | # | 20 | # |
6 | 21 | ############################################################################## | 21 | ############################################################################## |
7 | 22 | 22 | ||
8 | 23 | from collections import defaultdict | ||
9 | 23 | from openerp.osv import orm, fields | 24 | from openerp.osv import orm, fields |
10 | 24 | from openerp.tools.translate import _ | 25 | from openerp.tools.translate import _ |
11 | 26 | from openerp import pooler | ||
12 | 25 | import openerp.addons.decimal_precision as dp | 27 | import openerp.addons.decimal_precision as dp |
13 | 26 | from datetime import datetime | 28 | from datetime import datetime |
14 | 27 | from dateutil.relativedelta import relativedelta | 29 | from dateutil.relativedelta import relativedelta |
15 | @@ -213,6 +215,7 @@ | |||
16 | 213 | lines_to_create = [] | 215 | lines_to_create = [] |
17 | 214 | total_invoice_cur_accessory_cost = 0.0 | 216 | total_invoice_cur_accessory_cost = 0.0 |
18 | 215 | total_invoice_cur_product_value = 0.0 | 217 | total_invoice_cur_product_value = 0.0 |
19 | 218 | errors = defaultdict(list) | ||
20 | 216 | for line in invoice.invoice_line: | 219 | for line in invoice.invoice_line: |
21 | 217 | line_qty = line.quantity | 220 | line_qty = line.quantity |
22 | 218 | source_uom = line.uos_id | 221 | source_uom = line.uos_id |
23 | @@ -248,47 +251,77 @@ | |||
24 | 248 | total_invoice_cur_product_value += line.price_subtotal | 251 | total_invoice_cur_product_value += line.price_subtotal |
25 | 249 | invoice_currency_id_to_write = invoice.currency_id.id | 252 | invoice_currency_id_to_write = invoice.currency_id.id |
26 | 250 | 253 | ||
27 | 254 | weight_to_write = False | ||
28 | 255 | source_uom_id_to_write = False | ||
29 | 256 | intrastat_code_id_to_write = False | ||
30 | 257 | intrastat_code_to_write = False | ||
31 | 258 | quantity_to_write = False | ||
32 | 259 | intrastat_uom_id_to_write = False | ||
33 | 260 | product_country_origin_id_to_write = False | ||
34 | 261 | |||
35 | 251 | if not parent_values['is_fiscal_only']: | 262 | if not parent_values['is_fiscal_only']: |
36 | 252 | 263 | ||
37 | 253 | if not source_uom: | 264 | if not source_uom: |
39 | 254 | raise orm.except_orm(_('Error :'), _("Missing unit of measure on the line with %d product(s) '%s' on invoice '%s'.") % (line_qty, line.product_id.name, invoice.number)) | 265 | errors[line.id].append( |
40 | 266 | _("Missing unit of measure on the line with %d " | ||
41 | 267 | "product(s) '%s' on invoice '%s'.") % | ||
42 | 268 | (line_qty, line.product_id.name, invoice.number) | ||
43 | 269 | ) | ||
44 | 255 | else: | 270 | else: |
45 | 256 | source_uom_id_to_write = source_uom.id | 271 | source_uom_id_to_write = source_uom.id |
46 | 257 | 272 | ||
59 | 258 | if source_uom.id == kg_uom_id: | 273 | if source_uom.id == kg_uom_id: |
60 | 259 | weight_to_write = line_qty | 274 | weight_to_write = line_qty |
61 | 260 | elif source_uom.category_id.id == weight_uom_categ_id: | 275 | elif source_uom.category_id.id == weight_uom_categ_id: |
62 | 261 | dest_uom_kg = self.pool.get('product.uom').browse(cr, uid, | 276 | dest_uom_kg = self.pool.get('product.uom').browse(cr, uid, |
63 | 262 | kg_uom_id, context=context) | 277 | kg_uom_id, context=context) |
64 | 263 | weight_to_write = self.pool.get('product.uom')._compute_qty_obj(cr, uid, | 278 | weight_to_write = self.pool.get('product.uom')._compute_qty_obj(cr, uid, |
65 | 264 | source_uom, line_qty, dest_uom_kg, context=context) | 279 | source_uom, line_qty, dest_uom_kg, context=context) |
66 | 265 | elif source_uom.category_id.id == pce_uom_categ_id: | 280 | elif source_uom.category_id.id == pce_uom_categ_id: |
67 | 266 | if not line.product_id.weight_net: | 281 | if not line.product_id.weight_net: |
68 | 267 | raise orm.except_orm(_('Error :'), _("Missing net weight on product '%s'.") % (line.product_id.name)) | 282 | errors[line.id].append( |
69 | 268 | if source_uom.id == pce_uom_id: | 283 | _("Missing net weight on product '%s'.") % |
70 | 269 | weight_to_write = line.product_id.weight_net * line_qty | 284 | (line.product_id.name) |
71 | 285 | ) | ||
72 | 286 | elif source_uom.id == pce_uom_id: | ||
73 | 287 | weight_to_write = line.product_id.weight_net * line_qty | ||
74 | 288 | else: | ||
75 | 289 | dest_uom_pce = self.pool.get('product.uom').browse(cr, uid, | ||
76 | 290 | pce_uom_id, context=context) | ||
77 | 291 | # Here, I suppose that, on the product, the weight is per PCE and not per uom_id | ||
78 | 292 | weight_to_write = line.product_id.weight_net * self.pool.get('product.uom')._compute_qty_obj(cr, uid, source_uom, line_qty, dest_uom_pce, context=context) | ||
79 | 293 | |||
80 | 270 | else: | 294 | else: |
88 | 271 | dest_uom_pce = self.pool.get('product.uom').browse(cr, uid, | 295 | errors[line.id].append( |
89 | 272 | pce_uom_id, context=context) | 296 | _("Conversion from unit of measure '%s' to " |
90 | 273 | # Here, I suppose that, on the product, the weight is per PCE and not per uom_id | 297 | "'Kg' is not implemented yet.") % (source_uom.name) |
91 | 274 | weight_to_write = line.product_id.weight_net * self.pool.get('product.uom')._compute_qty_obj(cr, uid, source_uom, line_qty, dest_uom_pce, context=context) | 298 | ) |
85 | 275 | |||
86 | 276 | else: | ||
87 | 277 | raise orm.except_orm(_('Error :'), _("Conversion from unit of measure '%s' to 'Kg' is not implemented yet.") % (source_uom.name)) | ||
92 | 278 | 299 | ||
93 | 279 | product_intrastat_code = line.product_id.intrastat_id | 300 | product_intrastat_code = line.product_id.intrastat_id |
94 | 280 | if not product_intrastat_code: | 301 | if not product_intrastat_code: |
95 | 281 | # If the H.S. code is not set on the product, we check if it's set | 302 | # If the H.S. code is not set on the product, we check if it's set |
96 | 282 | # on it's related category | 303 | # on it's related category |
97 | 283 | product_intrastat_code = line.product_id.categ_id.intrastat_id | 304 | product_intrastat_code = line.product_id.categ_id.intrastat_id |
98 | 284 | if not product_intrastat_code: | ||
99 | 285 | raise orm.except_orm(_('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)) | ||
100 | 286 | intrastat_code_id_to_write = product_intrastat_code.id | ||
101 | 287 | 305 | ||
104 | 288 | if not product_intrastat_code.intrastat_code: | 306 | if not product_intrastat_code: |
105 | 289 | raise orm.except_orm(_('Error :'), _("Missing intrastat code on H.S. code '%s' (%s).") % (product_intrastat_code.name, product_intrastat_code.description)) | 307 | errors[line.id].append( |
106 | 308 | _("Missing H.S. code on product '%s' " | ||
107 | 309 | "or on it's related category '%s'.") % | ||
108 | 310 | (line.product_id.name, | ||
109 | 311 | line.product_id.categ_id.complete_name) | ||
110 | 312 | ) | ||
111 | 290 | else: | 313 | else: |
113 | 291 | intrastat_code_to_write = product_intrastat_code.intrastat_code | 314 | intrastat_code_id_to_write = product_intrastat_code.id |
114 | 315 | |||
115 | 316 | if not product_intrastat_code.intrastat_code: | ||
116 | 317 | errors[line.id].append( | ||
117 | 318 | _("Missing intrastat code on H.S. code " | ||
118 | 319 | "'%s' (%s).") % | ||
119 | 320 | (product_intrastat_code.name, | ||
120 | 321 | product_intrastat_code.description) | ||
121 | 322 | ) | ||
122 | 323 | else: | ||
123 | 324 | intrastat_code_to_write = product_intrastat_code.intrastat_code | ||
124 | 292 | 325 | ||
125 | 293 | if not product_intrastat_code.intrastat_uom_id: | 326 | if not product_intrastat_code.intrastat_uom_id: |
126 | 294 | intrastat_uom_id_to_write = False | 327 | intrastat_uom_id_to_write = False |
127 | @@ -302,7 +335,15 @@ | |||
128 | 302 | uid, source_uom, line_qty, | 335 | uid, source_uom, line_qty, |
129 | 303 | product_intrastat_code.intrastat_uom_id, context=context) | 336 | product_intrastat_code.intrastat_uom_id, context=context) |
130 | 304 | else: | 337 | else: |
132 | 305 | raise orm.except_orm(_('Error :'), _("On invoice '%s', the line with product '%s' has a unit of measure (%s) which can't be converted to UoM of it's intrastat code (%s).") % (invoice.number, line.product_id.name, source_uom_id_to_write, intrastat_uom_id_to_write)) | 338 | errors[line.id].append( |
133 | 339 | _("On invoice '%s', the line with product " | ||
134 | 340 | "'%s' has a unit of measure (%s) which can't " | ||
135 | 341 | "be converted to UoM of it's intrastat " | ||
136 | 342 | "code (%s).") % (invoice.number, | ||
137 | 343 | line.product_id.name, | ||
138 | 344 | source_uom_id_to_write, | ||
139 | 345 | intrastat_uom_id_to_write) | ||
140 | 346 | ) | ||
141 | 306 | 347 | ||
142 | 307 | # The origin country should only be declated on Import | 348 | # The origin country should only be declated on Import |
143 | 308 | if intrastat.type == 'export': | 349 | if intrastat.type == 'export': |
144 | @@ -321,26 +362,27 @@ | |||
145 | 321 | ('origin_country_id', '!=', False) | 362 | ('origin_country_id', '!=', False) |
146 | 322 | ], context=context) | 363 | ], context=context) |
147 | 323 | if not supplier_ids: | 364 | if not supplier_ids: |
151 | 324 | raise orm.except_orm(_('Error :'), | 365 | errors[line.id].append( |
152 | 325 | _("Missing country of origin on product '%s' or on it's supplier information for partner '%s'.") | 366 | _("Missing country of origin on product " |
153 | 326 | % (line.product_id.name, parent_values.get('origin_partner_name', 'none'))) | 367 | "'%s' or on it's supplier information for " |
154 | 368 | "partner '%s'.") % | ||
155 | 369 | (line.product_id.name, | ||
156 | 370 | parent_values.get('origin_partner_name', 'none')) | ||
157 | 371 | ) | ||
158 | 327 | else: | 372 | else: |
159 | 328 | product_country_origin_id_to_write = supplieri_obj.read(cr, uid, | 373 | product_country_origin_id_to_write = supplieri_obj.read(cr, uid, |
160 | 329 | supplier_ids[0], ['origin_country_id'], | 374 | supplier_ids[0], ['origin_country_id'], |
161 | 330 | context=context)['origin_country_id'][0] | 375 | context=context)['origin_country_id'][0] |
162 | 331 | else: | 376 | else: |
175 | 332 | raise orm.except_orm(_('Error :'), | 377 | errors[line.id].append( |
176 | 333 | _("Missing country of origin on product '%s' (it's not possible to get the country of origin from the 'supplier information' in this case because we don't know the supplier of this product for the invoice '%s').") | 378 | _("Missing country of origin on product " |
177 | 334 | % (line.product_id.name, invoice.number)) | 379 | "'%s' (it's not possible to get the country " |
178 | 335 | 380 | "of origin from the 'supplier information' " | |
179 | 336 | else: | 381 | "in this case because we don't know the " |
180 | 337 | weight_to_write = False | 382 | "supplier of this product for the " |
181 | 338 | source_uom_id_to_write = False | 383 | "invoice '%s').") % |
182 | 339 | intrastat_code_id_to_write = False | 384 | (line.product_id.name, invoice.number) |
183 | 340 | intrastat_code_to_write = False | 385 | ) |
172 | 341 | quantity_to_write = False | ||
173 | 342 | intrastat_uom_id_to_write = False | ||
174 | 343 | product_country_origin_id_to_write = False | ||
184 | 344 | 386 | ||
185 | 345 | 387 | ||
186 | 346 | create_new_line = True | 388 | create_new_line = True |
187 | @@ -388,24 +430,34 @@ | |||
188 | 388 | # is always True | 430 | # is always True |
189 | 389 | # So we should not block with a raise before the end of the loop on the | 431 | # So we should not block with a raise before the end of the loop on the |
190 | 390 | # invoice lines | 432 | # invoice lines |
191 | 433 | invoice_errors = [] | ||
192 | 391 | if lines_to_create: | 434 | if lines_to_create: |
193 | 435 | parent_values['partner_vat_to_write'] = False | ||
194 | 392 | if parent_values['is_vat_required']: | 436 | if parent_values['is_vat_required']: |
195 | 393 | # If I have invoice.intrastat_country_id and the invoice partner | 437 | # If I have invoice.intrastat_country_id and the invoice partner |
196 | 394 | # is outside the EU, then I look for the fiscal rep of the partner | 438 | # is outside the EU, then I look for the fiscal rep of the partner |
197 | 395 | if invoice.intrastat_country_id and not invoice.partner_id.country_id.intrastat: | 439 | if invoice.intrastat_country_id and not invoice.partner_id.country_id.intrastat: |
198 | 396 | if not invoice.partner_id.intrastat_fiscal_representative: | 440 | if not invoice.partner_id.intrastat_fiscal_representative: |
200 | 397 | raise orm.except_orm(_('Error :'), _("Missing fiscal representative for partner '%s'. It is required for invoice '%s' which has an invoice partner outside the EU but the goods were delivered to or received from inside the EU.") % (invoice.partner_id.name, invoice.number)) | 441 | invoice_errors.append( |
201 | 442 | _("Missing fiscal representative for partner " | ||
202 | 443 | "'%s'. It is required for invoice '%s' which " | ||
203 | 444 | "has an invoice partner outside the EU but " | ||
204 | 445 | "the goods were delivered to or received from " | ||
205 | 446 | "inside the EU.") % | ||
206 | 447 | (invoice.partner_id.name, invoice.number) | ||
207 | 448 | ) | ||
208 | 398 | else: | 449 | else: |
209 | 399 | parent_values['partner_vat_to_write'] = invoice.partner_id.intrastat_fiscal_representative.vat | 450 | parent_values['partner_vat_to_write'] = invoice.partner_id.intrastat_fiscal_representative.vat |
210 | 400 | # Otherwise, I just read the vat number on the partner of the invoice | 451 | # Otherwise, I just read the vat number on the partner of the invoice |
211 | 401 | else: | 452 | else: |
212 | 402 | 453 | ||
213 | 403 | if not invoice.partner_id.vat: | 454 | if not invoice.partner_id.vat: |
215 | 404 | raise orm.except_orm(_('Error :'), _("Missing VAT number on partner '%s'.") % invoice.partner_id.name) | 455 | invoice_errors.append( |
216 | 456 | _("Missing VAT number on partner '%s'.") % | ||
217 | 457 | invoice.partner_id.name | ||
218 | 458 | ) | ||
219 | 405 | else: | 459 | else: |
220 | 406 | parent_values['partner_vat_to_write'] = invoice.partner_id.vat | 460 | parent_values['partner_vat_to_write'] = invoice.partner_id.vat |
221 | 407 | else: | ||
222 | 408 | parent_values['partner_vat_to_write'] = False | ||
223 | 409 | 461 | ||
224 | 410 | for line_to_create in lines_to_create: | 462 | for line_to_create in lines_to_create: |
225 | 411 | line_to_create['partner_vat'] = parent_values['partner_vat_to_write'] | 463 | line_to_create['partner_vat'] = parent_values['partner_vat_to_write'] |
226 | @@ -422,7 +474,6 @@ | |||
227 | 422 | 474 | ||
228 | 423 | line_to_create['amount_invoice_currency'] = line_to_create['amount_product_value_inv_cur'] + line_to_create['amount_accessory_cost_inv_cur'] | 475 | line_to_create['amount_invoice_currency'] = line_to_create['amount_product_value_inv_cur'] + line_to_create['amount_accessory_cost_inv_cur'] |
229 | 424 | 476 | ||
230 | 425 | |||
231 | 426 | # We do currency conversion NOW | 477 | # We do currency conversion NOW |
232 | 427 | if invoice.currency_id.name != 'EUR': | 478 | if invoice.currency_id.name != 'EUR': |
233 | 428 | # for currency conversion | 479 | # for currency conversion |
234 | @@ -439,13 +490,13 @@ | |||
235 | 439 | for value in ['quantity', 'weight']: # These 2 fields are char | 490 | for value in ['quantity', 'weight']: # These 2 fields are char |
236 | 440 | if line_to_create[value]: | 491 | if line_to_create[value]: |
237 | 441 | line_to_create[value] = str(int(round(line_to_create[value], 0))) | 492 | line_to_create[value] = str(int(round(line_to_create[value], 0))) |
242 | 442 | line_obj.create(cr, uid, line_to_create, context=context) | 493 | if not errors and not invoice_errors: |
243 | 443 | 494 | line_obj.create(cr, uid, line_to_create, context=context) | |
244 | 444 | return True | 495 | |
245 | 445 | 496 | return invoice_errors, errors | |
246 | 446 | 497 | ||
247 | 447 | def compute_invoice_values(self, cr, uid, intrastat, invoice, parent_values, context=None): | 498 | def compute_invoice_values(self, cr, uid, intrastat, invoice, parent_values, context=None): |
249 | 448 | 499 | errors = [] | |
250 | 449 | intrastat_type = self.pool.get('report.intrastat.type').read(cr, uid, parent_values['intrastat_type_id_to_write'], context=context) | 500 | intrastat_type = self.pool.get('report.intrastat.type').read(cr, uid, parent_values['intrastat_type_id_to_write'], context=context) |
251 | 450 | parent_values['procedure_code_to_write'] = intrastat_type['procedure_code'] | 501 | parent_values['procedure_code_to_write'] = intrastat_type['procedure_code'] |
252 | 451 | parent_values['transaction_code_to_write'] = intrastat_type['transaction_code'] | 502 | parent_values['transaction_code_to_write'] = intrastat_type['transaction_code'] |
253 | @@ -456,10 +507,20 @@ | |||
254 | 456 | # force to is_fiscal_only | 507 | # force to is_fiscal_only |
255 | 457 | parent_values['is_fiscal_only'] = True | 508 | parent_values['is_fiscal_only'] = True |
256 | 458 | 509 | ||
257 | 510 | parent_values.update({ | ||
258 | 511 | 'department_to_write': False, | ||
259 | 512 | 'transport_to_write': False, | ||
260 | 513 | }) | ||
261 | 514 | parent_values.setdefault('partner_country_id_to_write', False) | ||
262 | 459 | if not parent_values['is_fiscal_only']: | 515 | if not parent_values['is_fiscal_only']: |
263 | 460 | if not invoice.intrastat_transport: | 516 | if not invoice.intrastat_transport: |
264 | 461 | if not intrastat.company_id.default_intrastat_transport: | 517 | if not intrastat.company_id.default_intrastat_transport: |
266 | 462 | raise orm.except_orm(_('Error :'), _("The mode of transport is not set on invoice '%s' nor the default mode of transport on the company '%s'.") % (invoice.number, intrastat.company_id.name)) | 518 | errors.append( |
267 | 519 | _("The mode of transport is not set on invoice '%s' " | ||
268 | 520 | "nor the default mode of transport on " | ||
269 | 521 | "the company '%s'.") % | ||
270 | 522 | (invoice.number, intrastat.company_id.name) | ||
271 | 523 | ) | ||
272 | 463 | else: | 524 | else: |
273 | 464 | parent_values['transport_to_write'] = intrastat.company_id.default_intrastat_transport | 525 | parent_values['transport_to_write'] = intrastat.company_id.default_intrastat_transport |
274 | 465 | else: | 526 | else: |
275 | @@ -467,18 +528,22 @@ | |||
276 | 467 | 528 | ||
277 | 468 | if not invoice.intrastat_department: | 529 | if not invoice.intrastat_department: |
278 | 469 | if not intrastat.company_id.default_intrastat_department: | 530 | if not intrastat.company_id.default_intrastat_department: |
280 | 470 | raise orm.except_orm(_('Error :'), _("The intrastat department hasn't been set on invoice '%s' and the default intrastat department is missing on the company '%s'.") % (invoice.number, intrastat.company_id.name)) | 531 | errors.append( |
281 | 532 | _("The intrastat department hasn't been set on " | ||
282 | 533 | "invoice '%s' and the default intrastat department " | ||
283 | 534 | "is missing on the company '%s'.") % | ||
284 | 535 | (invoice.number, intrastat.company_id.name) | ||
285 | 536 | ) | ||
286 | 471 | else: | 537 | else: |
287 | 472 | parent_values['department_to_write'] = intrastat.company_id.default_intrastat_department | 538 | parent_values['department_to_write'] = intrastat.company_id.default_intrastat_department |
288 | 473 | else: | 539 | else: |
289 | 474 | parent_values['department_to_write'] = invoice.intrastat_department | 540 | parent_values['department_to_write'] = invoice.intrastat_department |
290 | 475 | else: | 541 | else: |
297 | 476 | parent_values['department_to_write'] = False | 542 | parent_values.update({ |
298 | 477 | parent_values['transport_to_write'] = False | 543 | 'transaction_code_to_write': False, |
299 | 478 | parent_values['transaction_code_to_write'] = False | 544 | 'partner_country_id_to_write': False, |
300 | 479 | parent_values['partner_country_id_to_write'] = False | 545 | }) |
301 | 480 | #print "parent_values =", parent_values | 546 | return parent_values, errors |
296 | 481 | return parent_values | ||
302 | 482 | 547 | ||
303 | 483 | 548 | ||
304 | 484 | def generate_product_lines_from_invoice(self, cr, uid, ids, context=None): | 549 | def generate_product_lines_from_invoice(self, cr, uid, ids, context=None): |
305 | @@ -497,7 +562,7 @@ | |||
306 | 497 | if intrastat.type == 'import': | 562 | if intrastat.type == 'import': |
307 | 498 | # Les régularisations commerciales à l'HA ne sont PAS | 563 | # Les régularisations commerciales à l'HA ne sont PAS |
308 | 499 | # déclarées dans la DEB, cf page 50 du BOD 6883 du 06 janvier 2011 | 564 | # déclarées dans la DEB, cf page 50 du BOD 6883 du 06 janvier 2011 |
310 | 500 | invoice_type = ('in_invoice', 'POUET') # I need 'POUET' to make it a tuple | 565 | invoice_type = 'in_invoice', # must be a tuple |
311 | 501 | if intrastat.type == 'export': | 566 | if intrastat.type == 'export': |
312 | 502 | invoice_type = ('out_invoice', 'out_refund') | 567 | invoice_type = ('out_invoice', 'out_refund') |
313 | 503 | invoice_ids = invoice_obj.search(cr, uid, [ | 568 | invoice_ids = invoice_obj.search(cr, uid, [ |
314 | @@ -508,13 +573,15 @@ | |||
315 | 508 | ('company_id', '=', intrastat.company_id.id) | 573 | ('company_id', '=', intrastat.company_id.id) |
316 | 509 | ], order='date_invoice', context=context) | 574 | ], order='date_invoice', context=context) |
317 | 510 | #print "invoice_ids=", invoice_ids | 575 | #print "invoice_ids=", invoice_ids |
318 | 576 | errors = defaultdict(list) | ||
319 | 577 | line_errors = {} | ||
320 | 511 | for invoice in invoice_obj.browse(cr, uid, invoice_ids, context=context): | 578 | for invoice in invoice_obj.browse(cr, uid, invoice_ids, context=context): |
321 | 512 | #print "INVOICE num =", invoice.number | 579 | #print "INVOICE num =", invoice.number |
322 | 513 | parent_values = {} | 580 | parent_values = {} |
323 | 514 | 581 | ||
324 | 515 | # We should always have a country on partner_id | 582 | # We should always have a country on partner_id |
325 | 516 | if not invoice.partner_id.country_id: | 583 | if not invoice.partner_id.country_id: |
327 | 517 | raise orm.except_orm(_('Error :'), _("Missing country on partner '%s'.") % invoice.partner_id.name) | 584 | errors[invoice.id].append(_("Missing country on partner '%s'.") % invoice.partner_id.name) |
328 | 518 | 585 | ||
329 | 519 | # If I have no invoice.intrastat_country_id, which is the case the first month | 586 | # If I have no invoice.intrastat_country_id, which is the case the first month |
330 | 520 | # of the deployment of the module, then I use the country on invoice partner | 587 | # of the deployment of the module, then I use the country on invoice partner |
331 | @@ -540,17 +607,38 @@ | |||
332 | 540 | if intrastat.company_id.default_intrastat_type_out_invoice: | 607 | if intrastat.company_id.default_intrastat_type_out_invoice: |
333 | 541 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_invoice.id | 608 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_invoice.id |
334 | 542 | else: | 609 | else: |
336 | 543 | raise orm.except_orm(_('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)) | 610 | raise orm.except_orm( |
337 | 611 | _('Error'), | ||
338 | 612 | _("The intrastat type hasn't been set on " | ||
339 | 613 | "invoice '%s' and the 'default intrastat type " | ||
340 | 614 | "for customer invoice' is missing for " | ||
341 | 615 | "the company '%s'.") % (invoice.number, | ||
342 | 616 | intrastat.company_id.name) | ||
343 | 617 | ) | ||
344 | 544 | elif invoice.type == 'out_refund': | 618 | elif invoice.type == 'out_refund': |
345 | 545 | if intrastat.company_id.default_intrastat_type_out_refund: | 619 | if intrastat.company_id.default_intrastat_type_out_refund: |
346 | 546 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_refund.id | 620 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_refund.id |
347 | 547 | else: | 621 | else: |
349 | 548 | raise orm.except_orm(_('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)) | 622 | raise orm.except_orm( |
350 | 623 | _('Error'), | ||
351 | 624 | _("The intrastat type hasn't been set on refund " | ||
352 | 625 | "'%s' and the 'default intrastat type for " | ||
353 | 626 | "customer refund' is missing for the company" | ||
354 | 627 | "'%s'.") % (invoice.number, | ||
355 | 628 | intrastat.company_id.name) | ||
356 | 629 | ) | ||
357 | 549 | elif invoice.type == 'in_invoice': | 630 | elif invoice.type == 'in_invoice': |
358 | 550 | if intrastat.company_id.default_intrastat_type_in_invoice: | 631 | if intrastat.company_id.default_intrastat_type_in_invoice: |
359 | 551 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_in_invoice.id | 632 | parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_in_invoice.id |
360 | 552 | else: | 633 | else: |
362 | 553 | raise orm.except_orm(_('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)) | 634 | raise orm.except_orm( |
363 | 635 | _('Error'), | ||
364 | 636 | _("The intrastat type hasn't been set on invoice " | ||
365 | 637 | "'%s' and the 'Default intrastat type for " | ||
366 | 638 | "supplier invoice' is missing for the company " | ||
367 | 639 | "'%s'.") % (invoice.number, | ||
368 | 640 | intrastat.company_id.name) | ||
369 | 641 | ) | ||
370 | 554 | else: | 642 | else: |
371 | 555 | raise orm.except_orm(_('Error :'), "Hara kiri... we can't have a supplier refund") | 643 | raise orm.except_orm(_('Error :'), "Hara kiri... we can't have a supplier refund") |
372 | 556 | 644 | ||
373 | @@ -567,10 +655,88 @@ | |||
374 | 567 | parent_values['origin_partner_id'] = invoice.partner_id.id | 655 | parent_values['origin_partner_id'] = invoice.partner_id.id |
375 | 568 | parent_values['origin_partner_name'] = invoice.partner_id.name | 656 | parent_values['origin_partner_name'] = invoice.partner_id.name |
376 | 569 | 657 | ||
381 | 570 | parent_values = self.compute_invoice_values(cr, uid, intrastat, invoice, parent_values, context=context) | 658 | parent_values, vals_errors = self.compute_invoice_values( |
382 | 571 | 659 | cr, uid, intrastat, invoice, parent_values, context=context) | |
383 | 572 | self.create_intrastat_product_lines(cr, uid, ids, intrastat, invoice, parent_values, context=context) | 660 | if vals_errors: |
384 | 573 | 661 | errors[invoice.id] += vals_errors | |
385 | 662 | |||
386 | 663 | # message_post | ||
387 | 664 | create_errors, create_line_errors = self.create_intrastat_product_lines( | ||
388 | 665 | cr, uid, ids, intrastat, invoice, | ||
389 | 666 | parent_values, context=context) | ||
390 | 667 | |||
391 | 668 | if create_errors: | ||
392 | 669 | errors[invoice.id] += create_errors | ||
393 | 670 | if create_line_errors: | ||
394 | 671 | line_errors[invoice.id] = create_line_errors | ||
395 | 672 | |||
396 | 673 | if errors or line_errors: | ||
397 | 674 | message_template = _( | ||
398 | 675 | "<b>The generation of lines could not be completed " | ||
399 | 676 | "due to the following issues:</b>" | ||
400 | 677 | "<p>" | ||
401 | 678 | "%s" | ||
402 | 679 | "</p>" | ||
403 | 680 | ) | ||
404 | 681 | invoice_template = _( | ||
405 | 682 | "<b>Invoice %(name)s:</b>" | ||
406 | 683 | "<ul>" | ||
407 | 684 | "%(errors)s" | ||
408 | 685 | "</ul>" | ||
409 | 686 | "<ul>" | ||
410 | 687 | "%(lines)s" | ||
411 | 688 | "</ul>" | ||
412 | 689 | ) | ||
413 | 690 | lines_template = _( | ||
414 | 691 | "<b>Line %(name)s:</b>" | ||
415 | 692 | "<ul>" | ||
416 | 693 | "%(errors)s" | ||
417 | 694 | "</ul>" | ||
418 | 695 | ) | ||
419 | 696 | invoice_line_obj = self.pool['account.invoice.line'] | ||
420 | 697 | invoice_messages = [] | ||
421 | 698 | for invoice_id in invoice_ids: | ||
422 | 699 | line_message = [] | ||
423 | 700 | for line_id, line_errs in line_errors.get(invoice_id, {}).iteritems(): | ||
424 | 701 | line = invoice_line_obj.browse(cr, uid, line_id, | ||
425 | 702 | context=context) | ||
426 | 703 | line_msg = lines_template % { | ||
427 | 704 | 'name': line.name, | ||
428 | 705 | 'errors': ''.join("<li>%s</li>" % err for err | ||
429 | 706 | in line_errs) | ||
430 | 707 | } | ||
431 | 708 | line_message.append(line_msg) | ||
432 | 709 | |||
433 | 710 | invoice = invoice_obj.browse(cr, uid, invoice_id, | ||
434 | 711 | context=context) | ||
435 | 712 | inv_errs = errors.get(invoice_id, []) | ||
436 | 713 | if inv_errs or line_message: | ||
437 | 714 | invoice_message = invoice_template % { | ||
438 | 715 | 'name': invoice.number, | ||
439 | 716 | 'errors': ''.join("<li>%s</li>" % err for err | ||
440 | 717 | in inv_errs), | ||
441 | 718 | 'lines': ''.join(line_message), | ||
442 | 719 | } | ||
443 | 720 | invoice_messages.append(invoice_message) | ||
444 | 721 | message = message_template % ''.join(invoice_messages) | ||
445 | 722 | |||
446 | 723 | db = pooler.get_db(cr.dbname) | ||
447 | 724 | local_cr = db.cursor() | ||
448 | 725 | try: | ||
449 | 726 | self.message_post(local_cr, uid, ids, body=message, | ||
450 | 727 | subtype='mail.mt_comment', context=context) | ||
451 | 728 | except: | ||
452 | 729 | local_cr.rollback() | ||
453 | 730 | raise | ||
454 | 731 | else: | ||
455 | 732 | local_cr.commit() | ||
456 | 733 | finally: | ||
457 | 734 | local_cr.close() | ||
458 | 735 | raise orm.except_orm( | ||
459 | 736 | _('Error'), | ||
460 | 737 | _('The lines could not be generated, please ' | ||
461 | 738 | 'refresh the form and see the messages.') | ||
462 | 739 | ) | ||
463 | 574 | return True | 740 | return True |
464 | 575 | 741 | ||
465 | 576 | 742 |
I merged this earlier, but I found a regression tonight and I reverted the commit.
There is a regression in this MP : values[ 'is_fiscal_ only'] == True, that's why it was inside the "else"... and you removed the "else" !
the modifications l 235 and 269 are wrong : putting the keys in the parent_values dict to False should only be made when parent_
It may not be the only regression ; I think there is the same kind of thing on line 199.
You made some modifications to the "functionnal code" (it seems to me that you thought it was to clean-it-up) that are not linked to the error messaging system, but it causes some issues.