2014-08-07 12:58:07 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-03-13 14:18:36 +01:00
|
|
|
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
2014-08-07 12:58:07 +02:00
|
|
|
|
2017-03-13 14:18:36 +01:00
|
|
|
from odoo import models, api, fields, _
|
|
|
|
from odoo.exceptions import UserError
|
2014-08-07 12:58:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
class account_invoice(models.Model):
|
|
|
|
_inherit = "account.invoice"
|
|
|
|
|
2017-03-13 14:18:36 +01:00
|
|
|
already_validated = fields.Boolean(readonly=True, copy=False)
|
|
|
|
|
2014-08-07 12:58:07 +02:00
|
|
|
@api.multi
|
|
|
|
def action_move_create(self):
|
|
|
|
res = super(account_invoice, self).action_move_create()
|
|
|
|
for inv in self:
|
|
|
|
if inv.journal_id.check_chronology:
|
|
|
|
invoices = \
|
|
|
|
self.search([('state', 'not in',
|
2014-08-18 11:06:23 +02:00
|
|
|
['open', 'paid', 'cancel', 'proforma',
|
|
|
|
'proforma2']),
|
2014-08-07 12:58:07 +02:00
|
|
|
('date_invoice', '!=', False),
|
|
|
|
('date_invoice', '<', inv.date_invoice),
|
2014-08-18 11:06:23 +02:00
|
|
|
('journal_id', '=', inv.journal_id.id)],
|
|
|
|
limit=1)
|
2014-08-07 12:58:07 +02:00
|
|
|
if len(invoices) > 0:
|
2017-03-13 14:18:36 +01:00
|
|
|
date_invoice_format = fields.Date.\
|
|
|
|
from_string(inv.date_invoice)
|
2014-08-18 11:06:23 +02:00
|
|
|
date_invoice_tz = fields\
|
|
|
|
.Date.context_today(self, date_invoice_format)
|
2017-03-13 14:18:36 +01:00
|
|
|
raise UserError(_("Chronology Error. "
|
|
|
|
"Please confirm older draft "
|
|
|
|
"invoices before %s and try again.")
|
|
|
|
% date_invoice_tz)
|
|
|
|
if not inv.already_validated:
|
2014-08-07 12:58:07 +02:00
|
|
|
invoices = self.search([('state', 'in', ['open', 'paid']),
|
|
|
|
('date_invoice', '>',
|
|
|
|
inv.date_invoice),
|
|
|
|
('journal_id', '=',
|
2014-08-18 11:06:23 +02:00
|
|
|
inv.journal_id.id)],
|
|
|
|
limit=1)
|
2017-03-13 14:18:36 +01:00
|
|
|
|
2014-08-07 12:58:07 +02:00
|
|
|
if len(invoices) > 0:
|
2017-03-13 14:18:36 +01:00
|
|
|
date_invoice_format = fields.Date.\
|
|
|
|
from_string(inv.date_invoice)
|
2014-08-18 11:06:23 +02:00
|
|
|
date_invoice_tz = fields\
|
|
|
|
.Date.context_today(self, date_invoice_format)
|
2017-03-13 14:18:36 +01:00
|
|
|
raise UserError(_("Chronology Error. "
|
|
|
|
"There exist at least one invoice "
|
|
|
|
"with a date posterior to %s.") %
|
|
|
|
date_invoice_tz)
|
|
|
|
if not inv.already_validated:
|
|
|
|
inv.already_validated = True
|
2014-08-07 12:58:07 +02:00
|
|
|
return res
|