mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[IMP] account_invoice_constraint_chronology: black, isort, prettier
This commit is contained in:
committed by
Zina Rasoamanana
parent
2e68ed8bf7
commit
99ecd163a6
@@ -3,7 +3,7 @@
|
||||
|
||||
import datetime
|
||||
|
||||
from odoo import models, api, fields, _
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tools.misc import format_date
|
||||
|
||||
@@ -14,35 +14,34 @@ class AccountInvoice(models.Model):
|
||||
@api.model
|
||||
def _prepare_previous_invoices_domain(self, invoice):
|
||||
domain = [
|
||||
('state', 'not in', ['open',
|
||||
'paid',
|
||||
'cancel',
|
||||
'in_payment',
|
||||
'proforma',
|
||||
'proforma2']),
|
||||
('date_invoice', '!=', False),
|
||||
('date_invoice', '<', invoice.date_invoice),
|
||||
('journal_id', '=', invoice.journal_id.id),
|
||||
(
|
||||
"state",
|
||||
"not in",
|
||||
["open", "paid", "cancel", "in_payment", "proforma", "proforma2"],
|
||||
),
|
||||
("date_invoice", "!=", False),
|
||||
("date_invoice", "<", invoice.date_invoice),
|
||||
("journal_id", "=", invoice.journal_id.id),
|
||||
]
|
||||
if (
|
||||
invoice.journal_id.refund_sequence
|
||||
and invoice.journal_id.sequence_id != invoice.journal_id.refund_sequence_id
|
||||
):
|
||||
domain.append(('type', '=', invoice.type))
|
||||
domain.append(("type", "=", invoice.type))
|
||||
return domain
|
||||
|
||||
@api.model
|
||||
def _prepare_later_invoices_domain(self, invoice):
|
||||
domain = [
|
||||
('state', 'in', ['open', 'in_payment', 'paid']),
|
||||
('date_invoice', '>', invoice.date_invoice),
|
||||
('journal_id', '=', invoice.journal_id.id),
|
||||
("state", "in", ["open", "in_payment", "paid"]),
|
||||
("date_invoice", ">", invoice.date_invoice),
|
||||
("journal_id", "=", invoice.journal_id.id),
|
||||
]
|
||||
if (
|
||||
invoice.journal_id.refund_sequence
|
||||
and invoice.journal_id.sequence_id != invoice.journal_id.refund_sequence_id
|
||||
):
|
||||
domain.append(('type', '=', invoice.type))
|
||||
domain.append(("type", "=", invoice.type))
|
||||
return domain
|
||||
|
||||
@api.multi
|
||||
@@ -52,8 +51,7 @@ class AccountInvoice(models.Model):
|
||||
for inv in self:
|
||||
if not inv.journal_id.check_chronology:
|
||||
continue
|
||||
invoices = self.search(
|
||||
self._prepare_previous_invoices_domain(inv), limit=1)
|
||||
invoices = self.search(self._prepare_previous_invoices_domain(inv), limit=1)
|
||||
if invoices:
|
||||
date_invoice_format = datetime.datetime(
|
||||
year=inv.date_invoice.year,
|
||||
@@ -61,15 +59,18 @@ class AccountInvoice(models.Model):
|
||||
day=inv.date_invoice.day,
|
||||
)
|
||||
date_invoice_tz = format_date(
|
||||
self.env, fields.Date.context_today(
|
||||
self, date_invoice_format))
|
||||
raise UserError(_(
|
||||
"Chronology Error. Please confirm older draft invoices "
|
||||
"before {date_invoice} and try again.").format(
|
||||
date_invoice=date_invoice_tz))
|
||||
self.env, fields.Date.context_today(self, date_invoice_format)
|
||||
)
|
||||
raise UserError(
|
||||
_(
|
||||
"Chronology Error. Please confirm older draft invoices "
|
||||
"before {date_invoice} and try again."
|
||||
).format(date_invoice=date_invoice_tz)
|
||||
)
|
||||
if inv not in previously_validated:
|
||||
invoices = self.search(
|
||||
self._prepare_later_invoices_domain(inv), limit=1)
|
||||
self._prepare_later_invoices_domain(inv), limit=1
|
||||
)
|
||||
if invoices:
|
||||
date_invoice_format = datetime.datetime(
|
||||
year=inv.date_invoice.year,
|
||||
@@ -77,10 +78,12 @@ class AccountInvoice(models.Model):
|
||||
day=inv.date_invoice.day,
|
||||
)
|
||||
date_invoice_tz = format_date(
|
||||
self.env, fields.Date.context_today(
|
||||
self, date_invoice_format))
|
||||
raise UserError(_(
|
||||
"Chronology Error. There exist at least one invoice "
|
||||
"with a later date to {date_invoice}.").format(
|
||||
date_invoice=date_invoice_tz))
|
||||
self.env, fields.Date.context_today(self, date_invoice_format)
|
||||
)
|
||||
raise UserError(
|
||||
_(
|
||||
"Chronology Error. There exist at least one invoice "
|
||||
"with a later date to {date_invoice}."
|
||||
).format(date_invoice=date_invoice_tz)
|
||||
)
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user