Skip to content

Commit

Permalink
[MIG] account_move_name_sequence: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoBM authored and andreagidaltig committed Sep 28, 2023
1 parent 83dca14 commit f3c7cf8
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 25 deletions.
2 changes: 1 addition & 1 deletion account_move_name_sequence/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

{
"name": "Account Move Number Sequence",
"version": "15.0.1.1.0",
"version": "16.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"summary": "Generate journal entry number from sequence",
Expand Down
23 changes: 12 additions & 11 deletions account_move_name_sequence/models/account_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,18 @@ def _check_journal_sequence(self):
)
raise ValidationError(msg)

@api.model
def create(self, vals):
if not vals.get("sequence_id"):
vals["sequence_id"] = self._create_sequence(vals).id
if (
vals.get("type") in ("sale", "purchase")
and vals.get("refund_sequence")
and not vals.get("refund_sequence_id")
):
vals["refund_sequence_id"] = self._create_sequence(vals, refund=True).id
return super().create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if not vals.get("sequence_id"):
vals["sequence_id"] = self._create_sequence(vals).id
if (
vals.get("type") in ("sale", "purchase")
and vals.get("refund_sequence")
and not vals.get("refund_sequence_id")
):
vals["refund_sequence_id"] = self._create_sequence(vals, refund=True).id
return super().create(vals_list)

@api.model
def _prepare_sequence(self, vals, refund=False):
Expand Down
15 changes: 12 additions & 3 deletions account_move_name_sequence/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
* Alexis de Lattre <[email protected]>
* Moisés López <[email protected]>
* Francisco Luna <[email protected]>
* `Akretion <https://www.akretion.com>`_:

* Alexis de Lattre <[email protected]>

* `Vauxoo <https://www.vauxoo.com>`_:

* Moisés López <[email protected]>
* Francisco Luna <[email protected]>

* `Factor Libre <https://www.factorlibre.com>`_:

* Rodrigo Bonilla Martinez <[email protected]>
56 changes: 54 additions & 2 deletions account_move_name_sequence/tests/test_account_move_name_seq.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from freezegun import freeze_time

from odoo import fields
from odoo.exceptions import UserError
from odoo.exceptions import UserError, ValidationError
from odoo.tests import tagged
from odoo.tests.common import TransactionCase

Expand Down Expand Up @@ -168,7 +168,7 @@ def test_in_refund(self):
in_refund_invoice.action_post()
self.assertEqual(in_refund_invoice.name, move_name)

def test_remove_invoice_error(self):
def test_remove_invoice_error_secuence_no_grap(self):
invoice = self.env["account.move"].create(
{
"date": self.date,
Expand All @@ -189,3 +189,55 @@ def test_remove_invoice_error(self):
error_msg = "You cannot delete this entry, as it has already consumed a"
with self.assertRaisesRegex(UserError, error_msg):
invoice.unlink()

def test_remove_invoice_error_secuence_standard(self):
implementation = {"implementation": "standard"}
self.purchase_journal.sequence_id.write(implementation)
self.purchase_journal.refund_sequence_id.write(implementation)
in_refund_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_refund",
"invoice_line_ids": [
(
0,
0,
{
"account_id": self.account1.id,
"price_unit": 42.0,
"quantity": 12,
},
)
],
}
)
in_refund_invoice._compute_split_sequence()
self.assertEqual(in_refund_invoice.name, "/")
in_refund_invoice.action_post()
error_msg = "You cannot delete an item linked to a posted entry."
with self.assertRaisesRegex(UserError, error_msg):
in_refund_invoice.unlink()
in_refund_invoice.button_draft()
in_refund_invoice.button_cancel()
self.assertTrue(in_refund_invoice.unlink())

def test_journal_check_journal_sequence(self):
new_journal = self.purchase_journal.copy()
# same sequence_id and refund_sequence_id
with self.assertRaises(ValidationError):
new_journal.write({"refund_sequence_id": new_journal.sequence_id})

# company_id in sequence_id or refund_sequence_id to False
new_sequence_id = new_journal.sequence_id.copy({"company_id": False})
new_refund_sequence_id = new_journal.refund_sequence_id.copy(
{"company_id": False}
)
with self.assertRaises(ValidationError):
new_journal.write({"sequence_id": new_sequence_id.id})
with self.assertRaises(ValidationError):
new_journal.write({"refund_sequence_id": new_refund_sequence_id.id})

def test_constrains_date_sequence_true(self):
self.assertTrue(self.env["account.move"]._constrains_date_sequence())
16 changes: 8 additions & 8 deletions account_move_name_sequence/views/account_move.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<xpath
expr="//div[hasclass('oe_title')]/h1[hasclass('mt0')]"
position="attributes"
>
<attribute name="attrs">{'invisible': [('name', '=', '/')]}</attribute>
<xpath expr="//field[@name='highest_name']/.." position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath
expr="//div[hasclass('oe_title')]//field[@name='name']"
position="attributes"
>
<attribute name="attrs">{'readonly': 1}</attribute>
<attribute name="attrs">{'invisible': [('name', '=', '/')]}</attribute>
<attribute name="readonly">1</attribute>
</xpath>
<xpath expr="//field[@name='highest_name']/.." position="attributes">
<attribute name="attrs">{'invisible': 1}</attribute>
<xpath expr="//div[hasclass('oe_title')]//h1//span" position="attributes">
<attribute
name="attrs"
>{'invisible': ['|', ('state', '!=', 'draft'), ('name', '!=', '/')]}</attribute>
</xpath>
</field>
</record>
Expand Down

0 comments on commit f3c7cf8

Please sign in to comment.