@@ -19,6 +19,20 @@ class InvoiceMerge(models.TransientModel):
19
19
default = True )
20
20
date_invoice = fields .Date ('Invoice Date' )
21
21
22
+ @api .model
23
+ def _get_not_mergeable_invoices_message (self , invoices ):
24
+ """Overridable function to custom error message"""
25
+ key_fields = invoices ._get_invoice_key_cols ()
26
+ error_msg = {}
27
+ if len (invoices ) != len (invoices ._get_draft_invoices ()):
28
+ error_msg ['state' ] = (
29
+ _ ('Megeable State (ex : %s)' ) %
30
+ (invoices and invoices [0 ].state or _ ('Draf' )))
31
+ for field in key_fields :
32
+ if len (set (invoices .mapped (field ))) > 1 :
33
+ error_msg [field ] = invoices ._fields [field ].string
34
+ return error_msg
35
+
22
36
@api .model
23
37
def _dirty_check (self ):
24
38
if self .env .context .get ('active_model' , '' ) == 'account.invoice' :
@@ -29,29 +43,11 @@ def _dirty_check(self):
29
43
'view.' ))
30
44
31
45
invs = self .env ['account.invoice' ].browse (ids )
32
- for d in invs :
33
- if d ['state' ] != 'draft' :
34
- raise UserError (
35
- _ ('At least one of the selected invoices is %s!' ) %
36
- d ['state' ])
37
- if d ['account_id' ] != invs [0 ]['account_id' ]:
38
- raise UserError (
39
- _ ('Not all invoices use the same account!' ))
40
- if d ['company_id' ] != invs [0 ]['company_id' ]:
41
- raise UserError (
42
- _ ('Not all invoices are at the same company!' ))
43
- if d ['partner_id' ] != invs [0 ]['partner_id' ]:
44
- raise UserError (
45
- _ ('Not all invoices are for the same partner!' ))
46
- if d ['type' ] != invs [0 ]['type' ]:
47
- raise UserError (
48
- _ ('Not all invoices are of the same type!' ))
49
- if d ['currency_id' ] != invs [0 ]['currency_id' ]:
50
- raise UserError (
51
- _ ('Not all invoices are at the same currency!' ))
52
- if d ['journal_id' ] != invs [0 ]['journal_id' ]:
53
- raise UserError (
54
- _ ('Not all invoices are at the same journal!' ))
46
+ error_msg = self ._get_not_mergeable_invoices_message (invs )
47
+ if error_msg :
48
+ all_msg = _ ("All invoices must have the same: \n " )
49
+ all_msg += '\n ' .join ([value for value in error_msg .values ()])
50
+ raise UserError (all_msg )
55
51
return {}
56
52
57
53
@api .model
0 commit comments