Merge lp:~camptocamp/new-report-intrastat/7.0-post-all-errors-rather-than-one-by-one into lp:new-report-intrastat

Proposed by Guewen Baconnier @ Camptocamp
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
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_intrastat_product:

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.

To post a comment you must log in.
Revision history for this message
Alexis de Lattre (alexis-via) wrote :

I merged this earlier, but I found a regression tonight and I reverted the commit.

There is a regression in this MP :
the modifications l 235 and 269 are wrong : putting the keys in the parent_values dict to False should only be made when parent_values['is_fiscal_only'] == True, that's why it was inside the "else"... and you removed the "else" !

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.

Revision history for this message
Alexis de Lattre (alexis-via) :
review: Needs Fixing
Revision history for this message
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.

Revision history for this message
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.

Revision history for this message
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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'l10n_fr_intrastat_product/intrastat_product.py'
--- l10n_fr_intrastat_product/intrastat_product.py 2014-07-03 22:18:44 +0000
+++ l10n_fr_intrastat_product/intrastat_product.py 2014-08-12 13:38:07 +0000
@@ -20,8 +20,10 @@
20#20#
21##############################################################################21##############################################################################
2222
23from collections import defaultdict
23from openerp.osv import orm, fields24from openerp.osv import orm, fields
24from openerp.tools.translate import _25from openerp.tools.translate import _
26from openerp import pooler
25import openerp.addons.decimal_precision as dp27import openerp.addons.decimal_precision as dp
26from datetime import datetime28from datetime import datetime
27from dateutil.relativedelta import relativedelta29from dateutil.relativedelta import relativedelta
@@ -213,6 +215,7 @@
213 lines_to_create = []215 lines_to_create = []
214 total_invoice_cur_accessory_cost = 0.0216 total_invoice_cur_accessory_cost = 0.0
215 total_invoice_cur_product_value = 0.0217 total_invoice_cur_product_value = 0.0
218 errors = defaultdict(list)
216 for line in invoice.invoice_line:219 for line in invoice.invoice_line:
217 line_qty = line.quantity220 line_qty = line.quantity
218 source_uom = line.uos_id221 source_uom = line.uos_id
@@ -248,47 +251,77 @@
248 total_invoice_cur_product_value += line.price_subtotal251 total_invoice_cur_product_value += line.price_subtotal
249 invoice_currency_id_to_write = invoice.currency_id.id252 invoice_currency_id_to_write = invoice.currency_id.id
250253
254 weight_to_write = False
255 source_uom_id_to_write = False
256 intrastat_code_id_to_write = False
257 intrastat_code_to_write = False
258 quantity_to_write = False
259 intrastat_uom_id_to_write = False
260 product_country_origin_id_to_write = False
261
251 if not parent_values['is_fiscal_only']:262 if not parent_values['is_fiscal_only']:
252263
253 if not source_uom:264 if not source_uom:
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(
266 _("Missing unit of measure on the line with %d "
267 "product(s) '%s' on invoice '%s'.") %
268 (line_qty, line.product_id.name, invoice.number)
269 )
255 else:270 else:
256 source_uom_id_to_write = source_uom.id271 source_uom_id_to_write = source_uom.id
257272
258 if source_uom.id == kg_uom_id:273 if source_uom.id == kg_uom_id:
259 weight_to_write = line_qty274 weight_to_write = line_qty
260 elif source_uom.category_id.id == weight_uom_categ_id:275 elif source_uom.category_id.id == weight_uom_categ_id:
261 dest_uom_kg = self.pool.get('product.uom').browse(cr, uid,276 dest_uom_kg = self.pool.get('product.uom').browse(cr, uid,
262 kg_uom_id, context=context)277 kg_uom_id, context=context)
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,
264 source_uom, line_qty, dest_uom_kg, context=context)279 source_uom, line_qty, dest_uom_kg, context=context)
265 elif source_uom.category_id.id == pce_uom_categ_id:280 elif source_uom.category_id.id == pce_uom_categ_id:
266 if not line.product_id.weight_net:281 if not line.product_id.weight_net:
267 raise orm.except_orm(_('Error :'), _("Missing net weight on product '%s'.") % (line.product_id.name))282 errors[line.id].append(
268 if source_uom.id == pce_uom_id:283 _("Missing net weight on product '%s'.") %
269 weight_to_write = line.product_id.weight_net * line_qty284 (line.product_id.name)
285 )
286 elif source_uom.id == pce_uom_id:
287 weight_to_write = line.product_id.weight_net * line_qty
288 else:
289 dest_uom_pce = self.pool.get('product.uom').browse(cr, uid,
290 pce_uom_id, context=context)
291 # Here, I suppose that, on the product, the weight is per PCE and not per uom_id
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)
293
270 else:294 else:
271 dest_uom_pce = self.pool.get('product.uom').browse(cr, uid,295 errors[line.id].append(
272 pce_uom_id, context=context)296 _("Conversion from unit of measure '%s' to "
273 # Here, I suppose that, on the product, the weight is per PCE and not per uom_id297 "'Kg' is not implemented yet.") % (source_uom.name)
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 )
275
276 else:
277 raise orm.except_orm(_('Error :'), _("Conversion from unit of measure '%s' to 'Kg' is not implemented yet.") % (source_uom.name))
278299
279 product_intrastat_code = line.product_id.intrastat_id300 product_intrastat_code = line.product_id.intrastat_id
280 if not product_intrastat_code:301 if not product_intrastat_code:
281 # If the H.S. code is not set on the product, we check if it's set302 # If the H.S. code is not set on the product, we check if it's set
282 # on it's related category303 # on it's related category
283 product_intrastat_code = line.product_id.categ_id.intrastat_id304 product_intrastat_code = line.product_id.categ_id.intrastat_id
284 if not product_intrastat_code:
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))
286 intrastat_code_id_to_write = product_intrastat_code.id
287305
288 if not product_intrastat_code.intrastat_code:306 if not product_intrastat_code:
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(
308 _("Missing H.S. code on product '%s' "
309 "or on it's related category '%s'.") %
310 (line.product_id.name,
311 line.product_id.categ_id.complete_name)
312 )
290 else:313 else:
291 intrastat_code_to_write = product_intrastat_code.intrastat_code314 intrastat_code_id_to_write = product_intrastat_code.id
315
316 if not product_intrastat_code.intrastat_code:
317 errors[line.id].append(
318 _("Missing intrastat code on H.S. code "
319 "'%s' (%s).") %
320 (product_intrastat_code.name,
321 product_intrastat_code.description)
322 )
323 else:
324 intrastat_code_to_write = product_intrastat_code.intrastat_code
292325
293 if not product_intrastat_code.intrastat_uom_id:326 if not product_intrastat_code.intrastat_uom_id:
294 intrastat_uom_id_to_write = False327 intrastat_uom_id_to_write = False
@@ -302,7 +335,15 @@
302 uid, source_uom, line_qty,335 uid, source_uom, line_qty,
303 product_intrastat_code.intrastat_uom_id, context=context)336 product_intrastat_code.intrastat_uom_id, context=context)
304 else:337 else:
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(
339 _("On invoice '%s', the line with product "
340 "'%s' has a unit of measure (%s) which can't "
341 "be converted to UoM of it's intrastat "
342 "code (%s).") % (invoice.number,
343 line.product_id.name,
344 source_uom_id_to_write,
345 intrastat_uom_id_to_write)
346 )
306347
307 # The origin country should only be declated on Import348 # The origin country should only be declated on Import
308 if intrastat.type == 'export':349 if intrastat.type == 'export':
@@ -321,26 +362,27 @@
321 ('origin_country_id', '!=', False)362 ('origin_country_id', '!=', False)
322 ], context=context)363 ], context=context)
323 if not supplier_ids:364 if not supplier_ids:
324 raise orm.except_orm(_('Error :'),365 errors[line.id].append(
325 _("Missing country of origin on product '%s' or on it's supplier information for partner '%s'.")366 _("Missing country of origin on product "
326 % (line.product_id.name, parent_values.get('origin_partner_name', 'none')))367 "'%s' or on it's supplier information for "
368 "partner '%s'.") %
369 (line.product_id.name,
370 parent_values.get('origin_partner_name', 'none'))
371 )
327 else:372 else:
328 product_country_origin_id_to_write = supplieri_obj.read(cr, uid,373 product_country_origin_id_to_write = supplieri_obj.read(cr, uid,
329 supplier_ids[0], ['origin_country_id'],374 supplier_ids[0], ['origin_country_id'],
330 context=context)['origin_country_id'][0]375 context=context)['origin_country_id'][0]
331 else:376 else:
332 raise orm.except_orm(_('Error :'),377 errors[line.id].append(
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 "
334 % (line.product_id.name, invoice.number))379 "'%s' (it's not possible to get the country "
335380 "of origin from the 'supplier information' "
336 else:381 "in this case because we don't know the "
337 weight_to_write = False382 "supplier of this product for the "
338 source_uom_id_to_write = False383 "invoice '%s').") %
339 intrastat_code_id_to_write = False384 (line.product_id.name, invoice.number)
340 intrastat_code_to_write = False385 )
341 quantity_to_write = False
342 intrastat_uom_id_to_write = False
343 product_country_origin_id_to_write = False
344386
345387
346 create_new_line = True388 create_new_line = True
@@ -388,24 +430,34 @@
388 # is always True430 # is always True
389 # So we should not block with a raise before the end of the loop on the431 # So we should not block with a raise before the end of the loop on the
390 # invoice lines432 # invoice lines
433 invoice_errors = []
391 if lines_to_create:434 if lines_to_create:
435 parent_values['partner_vat_to_write'] = False
392 if parent_values['is_vat_required']:436 if parent_values['is_vat_required']:
393 # If I have invoice.intrastat_country_id and the invoice partner437 # If I have invoice.intrastat_country_id and the invoice partner
394 # is outside the EU, then I look for the fiscal rep of the partner438 # is outside the EU, then I look for the fiscal rep of the partner
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:
396 if not invoice.partner_id.intrastat_fiscal_representative:440 if not invoice.partner_id.intrastat_fiscal_representative:
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(
442 _("Missing fiscal representative for partner "
443 "'%s'. It is required for invoice '%s' which "
444 "has an invoice partner outside the EU but "
445 "the goods were delivered to or received from "
446 "inside the EU.") %
447 (invoice.partner_id.name, invoice.number)
448 )
398 else:449 else:
399 parent_values['partner_vat_to_write'] = invoice.partner_id.intrastat_fiscal_representative.vat450 parent_values['partner_vat_to_write'] = invoice.partner_id.intrastat_fiscal_representative.vat
400 # Otherwise, I just read the vat number on the partner of the invoice451 # Otherwise, I just read the vat number on the partner of the invoice
401 else:452 else:
402453
403 if not invoice.partner_id.vat:454 if not invoice.partner_id.vat:
404 raise orm.except_orm(_('Error :'), _("Missing VAT number on partner '%s'.") % invoice.partner_id.name)455 invoice_errors.append(
456 _("Missing VAT number on partner '%s'.") %
457 invoice.partner_id.name
458 )
405 else:459 else:
406 parent_values['partner_vat_to_write'] = invoice.partner_id.vat460 parent_values['partner_vat_to_write'] = invoice.partner_id.vat
407 else:
408 parent_values['partner_vat_to_write'] = False
409461
410 for line_to_create in lines_to_create:462 for line_to_create in lines_to_create:
411 line_to_create['partner_vat'] = parent_values['partner_vat_to_write']463 line_to_create['partner_vat'] = parent_values['partner_vat_to_write']
@@ -422,7 +474,6 @@
422474
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']
424476
425
426 # We do currency conversion NOW477 # We do currency conversion NOW
427 if invoice.currency_id.name != 'EUR':478 if invoice.currency_id.name != 'EUR':
428 # for currency conversion479 # for currency conversion
@@ -439,13 +490,13 @@
439 for value in ['quantity', 'weight']: # These 2 fields are char490 for value in ['quantity', 'weight']: # These 2 fields are char
440 if line_to_create[value]:491 if line_to_create[value]:
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)))
442 line_obj.create(cr, uid, line_to_create, context=context)493 if not errors and not invoice_errors:
443494 line_obj.create(cr, uid, line_to_create, context=context)
444 return True495
445496 return invoice_errors, errors
446497
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):
448499 errors = []
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)
450 parent_values['procedure_code_to_write'] = intrastat_type['procedure_code']501 parent_values['procedure_code_to_write'] = intrastat_type['procedure_code']
451 parent_values['transaction_code_to_write'] = intrastat_type['transaction_code']502 parent_values['transaction_code_to_write'] = intrastat_type['transaction_code']
@@ -456,10 +507,20 @@
456 # force to is_fiscal_only507 # force to is_fiscal_only
457 parent_values['is_fiscal_only'] = True508 parent_values['is_fiscal_only'] = True
458509
510 parent_values.update({
511 'department_to_write': False,
512 'transport_to_write': False,
513 })
514 parent_values.setdefault('partner_country_id_to_write', False)
459 if not parent_values['is_fiscal_only']:515 if not parent_values['is_fiscal_only']:
460 if not invoice.intrastat_transport:516 if not invoice.intrastat_transport:
461 if not intrastat.company_id.default_intrastat_transport:517 if not intrastat.company_id.default_intrastat_transport:
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(
519 _("The mode of transport is not set on invoice '%s' "
520 "nor the default mode of transport on "
521 "the company '%s'.") %
522 (invoice.number, intrastat.company_id.name)
523 )
463 else:524 else:
464 parent_values['transport_to_write'] = intrastat.company_id.default_intrastat_transport525 parent_values['transport_to_write'] = intrastat.company_id.default_intrastat_transport
465 else:526 else:
@@ -467,18 +528,22 @@
467528
468 if not invoice.intrastat_department:529 if not invoice.intrastat_department:
469 if not intrastat.company_id.default_intrastat_department:530 if not intrastat.company_id.default_intrastat_department:
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(
532 _("The intrastat department hasn't been set on "
533 "invoice '%s' and the default intrastat department "
534 "is missing on the company '%s'.") %
535 (invoice.number, intrastat.company_id.name)
536 )
471 else:537 else:
472 parent_values['department_to_write'] = intrastat.company_id.default_intrastat_department538 parent_values['department_to_write'] = intrastat.company_id.default_intrastat_department
473 else:539 else:
474 parent_values['department_to_write'] = invoice.intrastat_department540 parent_values['department_to_write'] = invoice.intrastat_department
475 else:541 else:
476 parent_values['department_to_write'] = False542 parent_values.update({
477 parent_values['transport_to_write'] = False543 'transaction_code_to_write': False,
478 parent_values['transaction_code_to_write'] = False544 'partner_country_id_to_write': False,
479 parent_values['partner_country_id_to_write'] = False545 })
480 #print "parent_values =", parent_values546 return parent_values, errors
481 return parent_values
482547
483548
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):
@@ -497,7 +562,7 @@
497 if intrastat.type == 'import':562 if intrastat.type == 'import':
498 # Les régularisations commerciales à l'HA ne sont PAS563 # Les régularisations commerciales à l'HA ne sont PAS
499 # déclarées dans la DEB, cf page 50 du BOD 6883 du 06 janvier 2011564 # déclarées dans la DEB, cf page 50 du BOD 6883 du 06 janvier 2011
500 invoice_type = ('in_invoice', 'POUET') # I need 'POUET' to make it a tuple565 invoice_type = 'in_invoice', # must be a tuple
501 if intrastat.type == 'export':566 if intrastat.type == 'export':
502 invoice_type = ('out_invoice', 'out_refund')567 invoice_type = ('out_invoice', 'out_refund')
503 invoice_ids = invoice_obj.search(cr, uid, [568 invoice_ids = invoice_obj.search(cr, uid, [
@@ -508,13 +573,15 @@
508 ('company_id', '=', intrastat.company_id.id)573 ('company_id', '=', intrastat.company_id.id)
509 ], order='date_invoice', context=context)574 ], order='date_invoice', context=context)
510 #print "invoice_ids=", invoice_ids575 #print "invoice_ids=", invoice_ids
576 errors = defaultdict(list)
577 line_errors = {}
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):
512 #print "INVOICE num =", invoice.number579 #print "INVOICE num =", invoice.number
513 parent_values = {}580 parent_values = {}
514581
515 # We should always have a country on partner_id582 # We should always have a country on partner_id
516 if not invoice.partner_id.country_id:583 if not invoice.partner_id.country_id:
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)
518585
519 # If I have no invoice.intrastat_country_id, which is the case the first month586 # If I have no invoice.intrastat_country_id, which is the case the first month
520 # of the deployment of the module, then I use the country on invoice partner587 # of the deployment of the module, then I use the country on invoice partner
@@ -540,17 +607,38 @@
540 if intrastat.company_id.default_intrastat_type_out_invoice:607 if intrastat.company_id.default_intrastat_type_out_invoice:
541 parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_invoice.id608 parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_invoice.id
542 else:609 else:
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(
611 _('Error'),
612 _("The intrastat type hasn't been set on "
613 "invoice '%s' and the 'default intrastat type "
614 "for customer invoice' is missing for "
615 "the company '%s'.") % (invoice.number,
616 intrastat.company_id.name)
617 )
544 elif invoice.type == 'out_refund':618 elif invoice.type == 'out_refund':
545 if intrastat.company_id.default_intrastat_type_out_refund:619 if intrastat.company_id.default_intrastat_type_out_refund:
546 parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_refund.id620 parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_out_refund.id
547 else:621 else:
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(
623 _('Error'),
624 _("The intrastat type hasn't been set on refund "
625 "'%s' and the 'default intrastat type for "
626 "customer refund' is missing for the company"
627 "'%s'.") % (invoice.number,
628 intrastat.company_id.name)
629 )
549 elif invoice.type == 'in_invoice':630 elif invoice.type == 'in_invoice':
550 if intrastat.company_id.default_intrastat_type_in_invoice:631 if intrastat.company_id.default_intrastat_type_in_invoice:
551 parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_in_invoice.id632 parent_values['intrastat_type_id_to_write'] = intrastat.company_id.default_intrastat_type_in_invoice.id
552 else:633 else:
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(
635 _('Error'),
636 _("The intrastat type hasn't been set on invoice "
637 "'%s' and the 'Default intrastat type for "
638 "supplier invoice' is missing for the company "
639 "'%s'.") % (invoice.number,
640 intrastat.company_id.name)
641 )
554 else:642 else:
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")
556644
@@ -567,10 +655,88 @@
567 parent_values['origin_partner_id'] = invoice.partner_id.id655 parent_values['origin_partner_id'] = invoice.partner_id.id
568 parent_values['origin_partner_name'] = invoice.partner_id.name656 parent_values['origin_partner_name'] = invoice.partner_id.name
569657
570 parent_values = self.compute_invoice_values(cr, uid, intrastat, invoice, parent_values, context=context)658 parent_values, vals_errors = self.compute_invoice_values(
571659 cr, uid, intrastat, invoice, parent_values, context=context)
572 self.create_intrastat_product_lines(cr, uid, ids, intrastat, invoice, parent_values, context=context)660 if vals_errors:
573661 errors[invoice.id] += vals_errors
662
663 # message_post
664 create_errors, create_line_errors = self.create_intrastat_product_lines(
665 cr, uid, ids, intrastat, invoice,
666 parent_values, context=context)
667
668 if create_errors:
669 errors[invoice.id] += create_errors
670 if create_line_errors:
671 line_errors[invoice.id] = create_line_errors
672
673 if errors or line_errors:
674 message_template = _(
675 "<b>The generation of lines could not be completed "
676 "due to the following issues:</b>"
677 "<p>"
678 "%s"
679 "</p>"
680 )
681 invoice_template = _(
682 "<b>Invoice %(name)s:</b>"
683 "<ul>"
684 "%(errors)s"
685 "</ul>"
686 "<ul>"
687 "%(lines)s"
688 "</ul>"
689 )
690 lines_template = _(
691 "<b>Line %(name)s:</b>"
692 "<ul>"
693 "%(errors)s"
694 "</ul>"
695 )
696 invoice_line_obj = self.pool['account.invoice.line']
697 invoice_messages = []
698 for invoice_id in invoice_ids:
699 line_message = []
700 for line_id, line_errs in line_errors.get(invoice_id, {}).iteritems():
701 line = invoice_line_obj.browse(cr, uid, line_id,
702 context=context)
703 line_msg = lines_template % {
704 'name': line.name,
705 'errors': ''.join("<li>%s</li>" % err for err
706 in line_errs)
707 }
708 line_message.append(line_msg)
709
710 invoice = invoice_obj.browse(cr, uid, invoice_id,
711 context=context)
712 inv_errs = errors.get(invoice_id, [])
713 if inv_errs or line_message:
714 invoice_message = invoice_template % {
715 'name': invoice.number,
716 'errors': ''.join("<li>%s</li>" % err for err
717 in inv_errs),
718 'lines': ''.join(line_message),
719 }
720 invoice_messages.append(invoice_message)
721 message = message_template % ''.join(invoice_messages)
722
723 db = pooler.get_db(cr.dbname)
724 local_cr = db.cursor()
725 try:
726 self.message_post(local_cr, uid, ids, body=message,
727 subtype='mail.mt_comment', context=context)
728 except:
729 local_cr.rollback()
730 raise
731 else:
732 local_cr.commit()
733 finally:
734 local_cr.close()
735 raise orm.except_orm(
736 _('Error'),
737 _('The lines could not be generated, please '
738 'refresh the form and see the messages.')
739 )
574 return True740 return True
575741
576742

Subscribers

People subscribed via source and target branches