Skip to content

Commit

Permalink
[FIX] account_move_name_sequence: call flush before _fetch_duplicate_…
Browse files Browse the repository at this point in the history
…supplier_reference method

same issue OCA#1501
this fix not working for v16 OCA#1514
  • Loading branch information
RodrigoBM authored and andreagidaltig committed Oct 9, 2023
1 parent e9e5cad commit a58e802
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
6 changes: 6 additions & 0 deletions account_move_name_sequence/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ def _is_end_of_seq_chain(self):
if not invoices_other_sequences and invoices_no_gap_sequences:
return False
return super(AccountMove, invoices_other_sequences)._is_end_of_seq_chain()

def _fetch_duplicate_supplier_reference(self, only_posted=False):
moves = self.filtered(lambda m: m.is_purchase_document() and m.ref)
if moves:
self.flush_model(["name", "journal_id", "move_type", "state"])
return super()._fetch_duplicate_supplier_reference(only_posted=only_posted)
96 changes: 96 additions & 0 deletions account_move_name_sequence/tests/test_account_move_name_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,102 @@ def test_prefix_move_name_use_move_date(self):
move.action_post()
self.assertEqual(move.name, "TEST-2022-07-0001")

def test_in_invoice_and_refund(self):
in_invoice = self.env["account.move"].create(
{
"journal_id": self.purchase_journal.id,
"invoice_date": self.date,
"partner_id": self.env.ref("base.res_partner_3").id,
"move_type": "in_invoice",
"invoice_line_ids": [
(
0,
0,
{
"account_id": self.account1.id,
"price_unit": 42.0,
"quantity": 12,
},
),
(
0,
0,
{
"account_id": self.account1.id,
"price_unit": 48.0,
"quantity": 10,
},
),
],
}
)
self.assertEqual(in_invoice.name, "/")
in_invoice.action_post()

move_reversal = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=in_invoice.ids)
.create(
{
"journal_id": in_invoice.journal_id.id,
"reason": "no reason",
"refund_method": "cancel",
}
)
)
reversal = move_reversal.reverse_moves()
reversed_move = self.env["account.move"].browse(reversal["res_id"])
self.assertTrue(reversed_move)
self.assertEqual(reversed_move.state, "posted")

in_invoice = in_invoice.copy(
{
"invoice_date": self.date,
}
)
in_invoice.action_post()

move_reversal = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=in_invoice.ids)
.create(
{
"journal_id": in_invoice.journal_id.id,
"reason": "no reason",
"refund_method": "modify",
}
)
)
reversal = move_reversal.reverse_moves()
draft_invoice = self.env["account.move"].browse(reversal["res_id"])
self.assertTrue(draft_invoice)
self.assertEqual(draft_invoice.state, "draft")
self.assertEqual(draft_invoice.move_type, "in_invoice")

in_invoice = in_invoice.copy(
{
"invoice_date": self.date,
}
)
in_invoice.action_post()

move_reversal = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=in_invoice.ids)
.create(
{
"journal_id": in_invoice.journal_id.id,
"reason": "no reason",
"refund_method": "refund",
}
)
)
reversal = move_reversal.reverse_moves()
draft_reversed_move = self.env["account.move"].browse(reversal["res_id"])
self.assertTrue(draft_reversed_move)
self.assertEqual(draft_reversed_move.state, "draft")
self.assertEqual(draft_reversed_move.move_type, "in_refund")

def test_in_refund(self):
in_refund_invoice = self.env["account.move"].create(
{
Expand Down

0 comments on commit a58e802

Please sign in to comment.