Skip to content

Commit

Permalink
[IMP] account_move_substate: mail template, views, tests
Browse files Browse the repository at this point in the history
[IMP] account_move_substate: Improve views

add substate to tree view, group buy and search

and fix form view

[IMP] account_move_substate: add tests

[IMP] account_move_substate: add tests

[IMP] account_move_substate: documentation
  • Loading branch information
bosd committed Jan 28, 2024
1 parent f208621 commit e2ab6ec
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 13 deletions.
3 changes: 2 additions & 1 deletion account_move_substate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Copyright 2021 Ecosoft (<http://ecosoft.co.th>)
# Copyright 2023 360ERP (<https://360ERP.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Account Move Sub State",
"version": "14.0.1.0.0",
"category": "Accounting & Finance",
"author": "Ecosoft, Odoo Community Association (OCA)",
"author": "360ERP, Ecosoft, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-invoicing",
"license": "AGPL-3",
"depends": ["account", "base_substate"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
<div>
Dear ${object.user_id.name or 'accounting user'},<br />
This email is to inform that your journal entry ${object.name} was verified by accounting manager.
<br /><br />
Thank you,
<br />
<br /><br />
Best Regards,
% if user.signature
<br />
${user.signature | safe}
% endif
</div>
</field>
<field name="auto_delete" eval="True" />
Expand Down
4 changes: 2 additions & 2 deletions account_move_substate/demo/account_move_substate_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<record id="base_substate_to_verify_account_move" model="base.substate">
<field name="name">To Verify</field>
<field name="sequence">1</field>
<field name="target_state_value_id" ref="target_state_value_posted" />
<field name="target_state_value_id" ref="target_state_value_draft" />
</record>
<record id="base_substate_checked_account_move" model="base.substate">
<field name="name">Checked</field>
<field name="sequence">2</field>
<field name="target_state_value_id" ref="target_state_value_posted" />
<field name="target_state_value_id" ref="target_state_value_draft" />
</record>
<record id="base_substate_verified_account_move" model="base.substate">
<field name="name">Verified</field>
Expand Down
17 changes: 17 additions & 0 deletions account_move_substate/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ class AccountMove(models.Model):
_inherit = ["account.move", "base.substate.mixin"]
_name = "account.move"
_state_field = "state"

def _track_template(self, changes):
res = super(AccountMove, self)._track_template(changes)
track = self[0]
if "substate_id" in changes and track.substate_id.mail_template_id:
res["substate_id"] = (
track.substate_id.mail_template_id,
{
"composition_mode": "comment",
"auto_delete_message": True,
"subtype_id": self.env["ir.model.data"].xmlid_to_res_id(
"mail.mt_note"
),
"email_layout_xmlid": "mail.mail_notification_light",
},
)
return res
4 changes: 4 additions & 0 deletions account_move_substate/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* `Ecosoft <http://ecosoft.co.th>`__:

* Pimolnat Suntian <[email protected]>

* `360ERP <https://360ERP.com>`__:

* Bosd <bosd>
4 changes: 2 additions & 2 deletions account_move_substate/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#. Go to ** Settings > Technical > Database Structure ** and Add "Base substate".
If necessery you can add "target State values" (ex define a substate for "cancel"
If necessary you can add "target State values" (ex define a substate for "cancel"
state).
Substate sequence is very important.
#. Create a journal entry and check if the substate are displayed on the header of
form view. Check if you can't set substate defined for journal entry if state is a draft.
form view. Check if you can't set substate defined for journal entry if state is a draft.
1 change: 1 addition & 0 deletions account_move_substate/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_account_move_substate
58 changes: 58 additions & 0 deletions account_move_substate/tests/test_account_move_substate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2023 bosd (<bosd>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase


class TestBaseSubstate(TransactionCase):
def setUp(self):
super(TestBaseSubstate, self).setUp()
self.substate_test_account_move = self.env["account.move"]
self.substate_test_account_move_line = self.env["account.move.line"]

self.substate_to_verify = self.env.ref(
"account_move_substate.base_substate_to_verify_account_move"
)
self.substate_checked = self.env.ref(
"account_move_substate.base_substate_checked_account_move"
)
self.substate_verified = self.env.ref(
"account_move_substate.base_substate_verified_account_move"
)

self.product = self.env["product.product"].create({"name": "Test"})

def test_account_move_substate(self):
partner = self.env.ref("base.res_partner_12")
invoice_test1 = self.substate_test_account_move.create(
{
# "name": "Test base substate to basic invoice",
"move_type": "out_invoice",
"partner_id": partner.id,
"invoice_line_ids": [
(
0,
0,
{
"name": "Test product",
"quantity": 1,
"price_unit": 450,
"tax_ids": [(6, 0, [])],
},
)
],
}
)

self.assertTrue(invoice_test1.state == "draft")

with self.assertRaises(ValidationError):
invoice_test1.substate_id = self.substate_verified
# post the invoice
invoice_test1.action_post()
self.assertTrue(invoice_test1.substate_id == self.substate_verified)

# test that there is no substate id
invoice_test1.button_cancel()
self.assertTrue(invoice_test1.state == "cancel")
self.assertTrue(not invoice_test1.substate_id)
41 changes: 36 additions & 5 deletions account_move_substate/views/account_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,44 @@
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<xpath expr="//header/field[@name='state']" position="before">
<field
<xpath expr="//header" position="after">
<header name="substate">
<field
name="substate_id"
widget="statusbar"
options="{'clickable': '1',}"
/>
</header>
</xpath>
</field>
</record>

<record id="view_invoice_tree" model="ir.ui.view">
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_invoice_tree" />
<field name="arch" type="xml">
<field name="state" position="after">
<field name="substate_id" widget="badge" optional="show" />
</field>
</field>
</record>

<record id="view_account_invoice_filter" model="ir.ui.view">
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_account_invoice_filter" />
<field name="arch" type="xml">
<field name="journal_id" position="after">
<field name="substate_id" />
</field>
<filter name="status" position="after">
<filter
name="substate_id"
widget="statusbar"
options="{'clickable': '1',}"
string="Substate"
domain="[]"
context="{'group_by':'substate_id'}"
/>
</xpath>
</filter>
</field>
</record>

</odoo>

0 comments on commit e2ab6ec

Please sign in to comment.