2
0

[IMP] - Chronology check depends on invoice type if journal is set to Dedicated Credit Note Sequence

This commit is contained in:
sbejaoui 2021-02-28 00:59:43 +01:00 committed by Zina Rasoamanana
parent f0ee046b14
commit c38dfc37e9
4 changed files with 45 additions and 2 deletions

View File

@ -21,12 +21,14 @@ msgstr ""
#. module: account_invoice_constraint_chronology #. module: account_invoice_constraint_chronology
#: code:addons/account_invoice_constraint_chronology/model/account_invoice.py:54 #: code:addons/account_invoice_constraint_chronology/model/account_invoice.py:54
#: code:addons/account_invoice_constraint_chronology/model/account_invoice.py:66
#, python-format #, python-format
msgid "Chronology Error. Please confirm older draft invoices before {date_invoice} and try again." msgid "Chronology Error. Please confirm older draft invoices before {date_invoice} and try again."
msgstr "" msgstr ""
#. module: account_invoice_constraint_chronology #. module: account_invoice_constraint_chronology
#: code:addons/account_invoice_constraint_chronology/model/account_invoice.py:70 #: code:addons/account_invoice_constraint_chronology/model/account_invoice.py:70
#: code:addons/account_invoice_constraint_chronology/model/account_invoice.py:82
#, python-format #, python-format
msgid "Chronology Error. There exist at least one invoice with a later date to {date_invoice}." msgid "Chronology Error. There exist at least one invoice with a later date to {date_invoice}."
msgstr "" msgstr ""

View File

@ -13,7 +13,7 @@ class AccountInvoice(models.Model):
@api.model @api.model
def _prepare_previous_invoices_domain(self, invoice): def _prepare_previous_invoices_domain(self, invoice):
return [ domain = [
('state', 'not in', ['open', ('state', 'not in', ['open',
'paid', 'paid',
'cancel', 'cancel',
@ -24,14 +24,26 @@ class AccountInvoice(models.Model):
('date_invoice', '<', invoice.date_invoice), ('date_invoice', '<', invoice.date_invoice),
('journal_id', '=', invoice.journal_id.id), ('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))
return domain
@api.model @api.model
def _prepare_later_invoices_domain(self, invoice): def _prepare_later_invoices_domain(self, invoice):
return [ domain = [
('state', 'in', ['open', 'in_payment', 'paid']), ('state', 'in', ['open', 'in_payment', 'paid']),
('date_invoice', '>', invoice.date_invoice), ('date_invoice', '>', invoice.date_invoice),
('journal_id', '=', invoice.journal_id.id), ('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))
return domain
@api.multi @api.multi
def action_move_create(self): def action_move_create(self):

View File

@ -2,3 +2,4 @@
* Gilles Gilles <meyomesse.gilles@gmail.com> * Gilles Gilles <meyomesse.gilles@gmail.com>
* Francesco Apruzzese <f.apruzzese@apuliasoftware.it> * Francesco Apruzzese <f.apruzzese@apuliasoftware.it>
* Thomas Binsfeld <thomas.binsfeld@acsone.eu> * Thomas Binsfeld <thomas.binsfeld@acsone.eu>
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>

View File

@ -133,3 +133,31 @@ class TestAccountConstraintChronology(common.SavepointCase):
self.account_journal_sale.type = 'bank' self.account_journal_sale.type = 'bank'
self.account_journal_sale._onchange_type() self.account_journal_sale._onchange_type()
self.assertFalse(self.account_journal_sale.check_chronology) self.assertFalse(self.account_journal_sale.check_chronology)
def test_invoice_refund(self):
journal = self.get_journal_check(True)
today = datetime.now()
tomorrow = today + timedelta(days=1)
date_tomorrow = tomorrow.strftime(DEFAULT_SERVER_DATE_FORMAT)
invoice_1 = self.create_simple_invoice(journal.id, date_tomorrow)
self.assertTrue(
(invoice_1.state == "draft"), "Initial invoice state is not Draft"
)
invoice_1.action_invoice_open()
date = today.strftime(DEFAULT_SERVER_DATE_FORMAT)
refund_invoice_wiz = (
self.env["account.invoice.refund"]
.with_context(active_ids=[invoice_1.id])
.create(
{
"description": "test_invoice_refund",
"filter_refund": "cancel",
"date": date,
"date_invoice": date,
}
)
)
with self.assertRaises(UserError):
refund_invoice_wiz.invoice_refund()
invoice_1.journal_id.refund_sequence = True
refund_invoice_wiz.invoice_refund()