[REF] Account Invoice Constraint Chronology: prepare methods for domains
This commit is contained in:
parent
507a99ce79
commit
25d91cda4e
@ -10,20 +10,36 @@ from odoo.exceptions import UserError
|
|||||||
class AccountInvoice(models.Model):
|
class AccountInvoice(models.Model):
|
||||||
_inherit = "account.invoice"
|
_inherit = "account.invoice"
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _prepare_previous_invoices_domain(self, invoice):
|
||||||
|
return [
|
||||||
|
('state', 'not in', ['open',
|
||||||
|
'paid',
|
||||||
|
'cancel',
|
||||||
|
'proforma',
|
||||||
|
'proforma2']),
|
||||||
|
('date_invoice', '!=', False),
|
||||||
|
('date_invoice', '<', invoice.date_invoice),
|
||||||
|
('journal_id', '=', invoice.journal_id.id),
|
||||||
|
]
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _prepare_later_invoices_domain(self, invoice):
|
||||||
|
return [
|
||||||
|
('state', 'in', ['open', 'paid']),
|
||||||
|
('date_invoice', '>', invoice.date_invoice),
|
||||||
|
('journal_id', '=', invoice.journal_id.id),
|
||||||
|
]
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_move_create(self):
|
def action_move_create(self):
|
||||||
previously_validated = self.filtered(lambda inv: inv.move_name)
|
previously_validated = self.filtered(lambda inv: inv.move_name)
|
||||||
res = super(AccountInvoice, self).action_move_create()
|
res = super(AccountInvoice, self).action_move_create()
|
||||||
for inv in self:
|
for inv in self:
|
||||||
if inv.journal_id.check_chronology:
|
if not inv.journal_id.check_chronology:
|
||||||
invoices = \
|
continue
|
||||||
self.search([('state', 'not in',
|
invoices = self.search(
|
||||||
['open', 'paid', 'cancel', 'proforma',
|
self._prepare_previous_invoices_domain(inv), limit=1)
|
||||||
'proforma2']),
|
|
||||||
('date_invoice', '!=', False),
|
|
||||||
('date_invoice', '<', inv.date_invoice),
|
|
||||||
('journal_id', '=', inv.journal_id.id)],
|
|
||||||
limit=1)
|
|
||||||
if invoices:
|
if invoices:
|
||||||
date_invoice_format = datetime.datetime(
|
date_invoice_format = datetime.datetime(
|
||||||
year=inv.date_invoice.year,
|
year=inv.date_invoice.year,
|
||||||
@ -32,18 +48,13 @@ class AccountInvoice(models.Model):
|
|||||||
)
|
)
|
||||||
date_invoice_tz = fields.Date.context_today(
|
date_invoice_tz = fields.Date.context_today(
|
||||||
self, date_invoice_format)
|
self, date_invoice_format)
|
||||||
raise UserError(_("Chronology Error. "
|
raise UserError(_(
|
||||||
"Please confirm older draft "
|
"Chronology Error. Please confirm older draft invoices "
|
||||||
"invoices before %s and try again.")
|
"before {date_invoice} and try again.").format(
|
||||||
% date_invoice_tz)
|
date_invoice=date_invoice_tz))
|
||||||
if inv not in previously_validated:
|
if inv not in previously_validated:
|
||||||
invoices = self.search([('state', 'in', ['open', 'paid']),
|
invoices = self.search(
|
||||||
('date_invoice', '>',
|
self._prepare_later_invoices_domain(inv), limit=1)
|
||||||
inv.date_invoice),
|
|
||||||
('journal_id', '=',
|
|
||||||
inv.journal_id.id)],
|
|
||||||
limit=1)
|
|
||||||
|
|
||||||
if invoices:
|
if invoices:
|
||||||
date_invoice_format = datetime.datetime(
|
date_invoice_format = datetime.datetime(
|
||||||
year=inv.date_invoice.year,
|
year=inv.date_invoice.year,
|
||||||
@ -52,8 +63,8 @@ class AccountInvoice(models.Model):
|
|||||||
)
|
)
|
||||||
date_invoice_tz = fields.Date.context_today(
|
date_invoice_tz = fields.Date.context_today(
|
||||||
self, date_invoice_format)
|
self, date_invoice_format)
|
||||||
raise UserError(_("Chronology Error. "
|
raise UserError(_(
|
||||||
"There exist at least one invoice "
|
"Chronology Error. There exist at least one invoice "
|
||||||
"with a later date to %s.") %
|
"with a later date to {date_invoice}.").format(
|
||||||
date_invoice_tz)
|
date_invoice=date_invoice_tz))
|
||||||
return res
|
return res
|
||||||
|
Loading…
Reference in New Issue
Block a user