Do not allow to create line or tax on invoice not in draft
Adding new line or tax should also be forbidden for validated state.
This commit is contained in:
@@ -2561,13 +2561,11 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
Invoice = Pool().get('account.invoice')
|
||||
invoice_ids = []
|
||||
for vals in vlist:
|
||||
if vals.get('invoice'):
|
||||
invoice_ids.append(vals.get('invoice'))
|
||||
for invoice in Invoice.browse(invoice_ids):
|
||||
if invoice.state in ('posted', 'paid', 'cancelled'):
|
||||
pool = Pool()
|
||||
Invoice = pool.get('account.invoice')
|
||||
invoice_ids = filter(None, {v.get('invoice') for v in vlist})
|
||||
for invoice in Invoice.browse(list(invoice_ids)):
|
||||
if invoice.state != 'draft':
|
||||
raise AccessError(
|
||||
gettext('account_invoice.msg_invoice_line_create',
|
||||
invoice=invoice.rec_name))
|
||||
@@ -2904,15 +2902,13 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
|
||||
|
||||
@classmethod
|
||||
def create(cls, vlist):
|
||||
Invoice = Pool().get('account.invoice')
|
||||
invoice_ids = []
|
||||
for vals in vlist:
|
||||
if vals.get('invoice'):
|
||||
invoice_ids.append(vals['invoice'])
|
||||
for invoice in Invoice.browse(invoice_ids):
|
||||
if invoice.state in ('posted', 'paid', 'cancelled'):
|
||||
pool = Pool()
|
||||
Invoice = pool.get('account.invoice')
|
||||
invoice_ids = filter(None, {v.get('invoice') for v in vlist})
|
||||
for invoice in Invoice.browse(list(invoice_ids)):
|
||||
if invoice.state != 'draft':
|
||||
raise AccessError(
|
||||
gettext('account_invoice.msg_invoice_tax_create',
|
||||
gettext('account_invoice.msg_invoice_tax_create_draft',
|
||||
invoice=invoice.rec_name))
|
||||
return super(InvoiceTax, cls).create(vlist)
|
||||
|
||||
|
||||
@@ -51,14 +51,14 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<record model="ir.message" id="msg_invoice_line_modify">
|
||||
<field name="text">You cannot modify line "%(line)s" because its invoice "%(invoice)s" is posted, paid or cancelled.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_invoice_line_create">
|
||||
<field name="text">You cannot add a line to invoice "%(invoice)s" because it is posted, paid or cancelled.</field>
|
||||
<record model="ir.message" id="msg_invoice_line_create_draft">
|
||||
<field name="text">You cannot add lines to invoice "%(invoice)s" because it is no longer in a draft state.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_invoice_tax_modify">
|
||||
<field name="text">You cannot modify tax "%(tax)s" because its invoice "%(invoice)s" is posted, paid or cancelled.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_invoice_tax_create">
|
||||
<field name="text">You cannot add a tax to invoice "%(invoice)s" because it is posted, paid or cancelled.</field>
|
||||
<field name="text">You cannot add taxes to invoice "%(invoice)s" because it is no longer in a draft state.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_invoice_line_tax_unique">
|
||||
<field name="text">A tax can be added only once to an invoice line.</field>
|
||||
|
||||
Reference in New Issue
Block a user