[14.0][MIG] agreement_account (Version 12.0 to 14.0)

[MIG] Prettier and Black

[MIG] Prettier

[MIG] Fixed Tracking

[ADD]Added the Tests.

[IMP]Improved the Tests.
This commit is contained in:
Patrick Wilson
2021-05-18 13:32:02 -06:00
parent 639178529a
commit 83e7c0ee9c
11 changed files with 209 additions and 140 deletions

View File

@@ -14,13 +14,13 @@ Agreement Account
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github
:target: https://github.com/OCA/contract/tree/12.0/agreement_account :target: https://github.com/OCA/contract/tree/14.0/agreement_account
:alt: OCA/contract :alt: OCA/contract
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/contract-12-0/contract-12-0-agreement_account :target: https://translation.odoo-community.org/projects/contract-12-0/contract-12-0-agreement_account
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/110/12.0 :target: https://runbot.odoo-community.org/runbot/110/14.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@@ -79,6 +79,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-alexis-via| |maintainer-bealdav| |maintainer-alexis-via| |maintainer-bealdav|
This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/12.0/agreement_account>`_ project on GitHub. This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/14.0/agreement_account>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -3,26 +3,26 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{ {
'name': 'Agreement Account', "name": "Agreement Account",
'summary': "Agreement on invoices", "summary": "Agreement on invoices",
'version': '12.0.1.0.0', "version": "14.0.1.0.0",
'category': 'Contract', "category": "Contract",
'author': 'Akretion, Odoo Community Association (OCA)', "author": "Akretion, Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/contract', "website": "https://github.com/OCA/contract",
'license': 'AGPL-3', "license": "AGPL-3",
'depends': [ "depends": [
'agreement', "agreement",
'account', "account",
], ],
'data': [ "data": [
'security/ir.model.access.csv', "security/ir.model.access.csv",
'views/agreement.xml', "views/agreement.xml",
'views/account_invoice.xml', "views/account_move.xml",
], ],
'development_status': 'Beta', "development_status": "Beta",
'maintainers': [ "maintainers": [
'alexis-via', "alexis-via",
'bealdav', "bealdav",
], ],
'installable': True, "installable": True,
} }

View File

@@ -1,2 +1,2 @@
from . import account_move
from . import agreement from . import agreement
from . import account_invoice

View File

@@ -1,15 +0,0 @@
# Copyright 2017-2020 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
agreement_id = fields.Many2one(
comodel_name='agreement', string='Agreement', ondelete='restrict',
track_visibility='onchange', readonly=True, copy=False,
states={'draft': [('readonly', False)]})

View File

@@ -0,0 +1,20 @@
# Copyright 2017-2020 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class AccountMove(models.Model):
_inherit = "account.move"
agreement_id = fields.Many2one(
comodel_name="agreement",
string="Agreement",
ondelete="restrict",
tracking=True,
readonly=True,
copy=False,
states={"draft": [("readonly", False)]},
)

View File

@@ -7,30 +7,33 @@ from odoo import fields, models
class Agreement(models.Model): class Agreement(models.Model):
_inherit = 'agreement' _inherit = "agreement"
invoice_ids = fields.One2many( invoice_ids = fields.One2many(
'account.invoice', 'agreement_id', string='Invoices', readonly=True) "account.move", "agreement_id", string="Invoices", readonly=True
)
out_invoice_count = fields.Integer( out_invoice_count = fields.Integer(
compute='_compute_invoice_count', string='# of Customer Invoices') compute="_compute_invoice_count", string="# of Customer Invoices"
)
in_invoice_count = fields.Integer( in_invoice_count = fields.Integer(
compute='_compute_invoice_count', string='# of Vendor Bills') compute="_compute_invoice_count", string="# of Vendor Bills"
)
def _compute_invoice_count(self): def _compute_invoice_count(self):
base_domain = [ base_domain = [("agreement_id", "in", self.ids)]
('agreement_id', 'in', self.ids), aio = self.env["account.move"]
('state', 'not in', ('draft', 'cancel'))]
aio = self.env['account.invoice']
out_rg_res = aio.read_group( out_rg_res = aio.read_group(
base_domain + [('type', 'in', ('out_invoice', 'out_refund'))], base_domain + [("move_type", "in", ("out_invoice", "out_refund"))],
['agreement_id'], ['agreement_id']) ["agreement_id"],
out_data = dict( ["agreement_id"],
[(x['agreement_id'][0], x['agreement_id_count']) for x in out_rg_res]) )
out_data = {x["agreement_id"][0]: x["agreement_id_count"] for x in out_rg_res}
in_rg_res = aio.read_group( in_rg_res = aio.read_group(
base_domain + [('type', 'in', ('in_invoice', 'in_refund'))], base_domain + [("move_type", "in", ("in_invoice", "in_refund"))],
['agreement_id'], ['agreement_id']) ["agreement_id"],
in_data = dict( ["agreement_id"],
[(x['agreement_id'][0], x['agreement_id_count']) for x in in_rg_res]) )
in_data = {x["agreement_id"][0]: x["agreement_id_count"] for x in in_rg_res}
for agreement in self: for agreement in self:
agreement.out_invoice_count = out_data.get(agreement.id, 0) agreement.out_invoice_count = out_data.get(agreement.id, 0)
agreement.in_invoice_count = in_data.get(agreement.id, 0) agreement.in_invoice_count = in_data.get(agreement.id, 0)

View File

@@ -0,0 +1 @@
from . import test_agreement

View File

@@ -0,0 +1,31 @@
# Copyright 2017-2020 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
class TestAgreement(TransactionCase):
def setUp(self):
super().setUp()
self.test_customer = self.env["res.partner"].create({"name": "TestCustomer"})
self.test_agreement_sale = self.env["agreement"].create(
{
"name": "TestAgreement-Sale",
"code": "SALE",
"partner_id": self.test_customer.id,
"domain": "sale",
}
)
self.test_agreement_purchase = self.env["agreement"].create(
{
"name": "TestAgreement-Purchase",
"code": "PURCHASE",
"partner_id": self.test_customer.id,
"domain": "purchase",
}
)
def test_compute_invoice_count(self):
self.test_agreement_sale._compute_invoice_count()
self.test_agreement_purchase._compute_invoice_count()

View File

@@ -1,54 +0,0 @@
<?xml version="1.0"?>
<!--
Copyright 2017-2020 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="invoice_form" model="ir.ui.view">
<field name="name">agreement.customer.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='other_info']/group/group/field[@name='name']" position="after">
<field name="agreement_id"
domain="[('partner_id', 'child_of', commercial_partner_id), ('domain', '=', 'sale')]"
context="{'default_partner_id': commercial_partner_id, 'default_domain': 'sale'}"/>
<field name="commercial_partner_id" invisible="1"/>
</xpath>
</field>
</record>
<record id="invoice_supplier_form" model="ir.ui.view">
<field name="name">agreement.supplier.invoice.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<xpath expr="//page/group/group/field[@name='company_id']" position="after">
<field name="agreement_id"
domain="[('partner_id', 'child_of', commercial_partner_id), ('domain', '=', 'purchase')]"
context="{'default_partner_id': commercial_partner_id, 'default_domain': 'purchase'}"/>
</xpath>
</field>
</record>
<record id="view_account_invoice_filter" model="ir.ui.view">
<field name="name">agreement.account.invoice.search</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.view_account_invoice_filter"/>
<field name="arch" type="xml">
<field name="date" position="after">
<field name="agreement_id"/>
</field>
<group expand="0" position="inside">
<filter string="Agreement" name="agreement_groupby"
context="{'group_by': 'agreement_id'}"/>
</group>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,58 @@
<!-- Copyright 2017-2020 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).-->
<odoo>
<record id="invoice_form" model="ir.ui.view">
<field name="name">agreement.customer.invoice.form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<xpath
expr="//page[@name='other_info']/group/group/field[@name='ref']"
position="after"
>
<field
name="agreement_id"
domain="[('partner_id', 'child_of', commercial_partner_id), ('domain', '=', 'sale')]"
context="{'default_partner_id': commercial_partner_id, 'default_domain': 'sale'}"
/>
<field name="commercial_partner_id" invisible="1" />
</xpath>
</field>
</record>
<record id="invoice_supplier_form" model="ir.ui.view">
<field name="name">agreement.supplier.invoice.form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<xpath expr="//page/group/group/field[@name='company_id']" position="after">
<field
name="agreement_id"
domain="[('partner_id', 'child_of', commercial_partner_id), ('domain', '=', 'purchase')]"
context="{'default_partner_id': commercial_partner_id, 'default_domain': 'purchase'}"
/>
</xpath>
</field>
</record>
<record id="view_account_invoice_filter" model="ir.ui.view">
<field name="name">agreement.account.move.search</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_account_invoice_filter" />
<field name="arch" type="xml">
<field name="date" position="after">
<field name="agreement_id" />
</field>
<group expand="0" position="inside">
<filter
string="Agreement"
name="agreement_groupby"
context="{'group_by': 'agreement_id'}"
/>
</group>
</field>
</record>
</odoo>

View File

@@ -1,5 +1,3 @@
<?xml version="1.0"?>
<odoo> <odoo>
<record id="agreement.agreement_menu" model="ir.ui.menu"> <record id="agreement.agreement_menu" model="ir.ui.menu">
@@ -7,29 +5,43 @@
<field name="sequence">150</field> <field name="sequence">150</field>
</record> </record>
<menuitem id="agreement_type_menu" action="agreement.agreement_type_action" <menuitem
parent="account.account_management_menu" sequence="155" id="agreement_type_menu"
groups="agreement.group_use_agreement_type"/> action="agreement.agreement_type_action"
parent="account.account_management_menu"
sequence="155"
groups="agreement.group_use_agreement_type"
/>
<record id="account_invoice_in_invoice_refund_action" model="ir.actions.act_window"> <record id="account_invoice_in_invoice_refund_action" model="ir.actions.act_window">
<field name="name">Vendor Bills</field> <field name="name">Vendor Bills</field>
<field name="res_model">account.invoice</field> <field name="res_model">account.move</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
<field name="domain">[('type','in', ('in_invoice', 'in_refund')), ('state', 'not in', ('draft', 'cancel'))]</field> <field
<field name="context">{'default_type': 'in_invoice', 'type': 'in_invoice', 'journal_type': 'purchase'}</field> name="domain"
>[('move_type','in', ('in_invoice', 'in_refund')), ('state', 'not in', ('draft', 'cancel'))]</field>
<field
name="context"
>{'default_type': 'in_invoice', 'move_type': 'in_invoice', 'journal_type': 'purchase'}</field>
</record> </record>
<record id="account_invoice_in_invoice_refund_action_tree" model="ir.actions.act_window.view"> <record
id="account_invoice_in_invoice_refund_action_tree"
model="ir.actions.act_window.view"
>
<field name="sequence" eval="10" /> <field name="sequence" eval="10" />
<field name="view_mode">tree</field> <field name="view_mode">tree</field>
<field name="view_id" ref="account.invoice_supplier_tree"/> <field name="view_id" ref="account.view_in_invoice_tree" />
<field name="act_window_id" ref="account_invoice_in_invoice_refund_action" /> <field name="act_window_id" ref="account_invoice_in_invoice_refund_action" />
</record> </record>
<record id="account_invoice_in_invoice_refund_action_form" model="ir.actions.act_window.view"> <record
id="account_invoice_in_invoice_refund_action_form"
model="ir.actions.act_window.view"
>
<field name="sequence" eval="20" /> <field name="sequence" eval="20" />
<field name="view_mode">form</field> <field name="view_mode">form</field>
<field name="view_id" ref="account.invoice_supplier_form"/> <field name="view_id" ref="account.view_move_form" />
<field name="act_window_id" ref="account_invoice_in_invoice_refund_action" /> <field name="act_window_id" ref="account_invoice_in_invoice_refund_action" />
</record> </record>
@@ -39,21 +51,34 @@
<field name="inherit_id" ref="agreement.agreement_form" /> <field name="inherit_id" ref="agreement.agreement_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<div name="button_box" position="inside"> <div name="button_box" position="inside">
<button class="oe_stat_button" type="action" <button
name="%(account.action_invoice_refund_out_tree)d" class="oe_stat_button"
type="action"
name="%(account.action_move_out_invoice_type)d"
context="{'search_default_agreement_id': active_id, 'default_agreement_id': active_id, 'default_partner_id': partner_id}" context="{'search_default_agreement_id': active_id, 'default_agreement_id': active_id, 'default_partner_id': partner_id}"
attrs="{'invisible': [('domain', '!=', 'sale')]}" attrs="{'invisible': [('domain', '!=', 'sale')]}"
icon="fa-pencil-square-o"> icon="fa-pencil-square-o"
<field string="Customer Invoices" name="out_invoice_count" widget="statinfo"/> >
<field
string="Invoices"
name="out_invoice_count"
widget="statinfo"
/>
</button> </button>
<button class="oe_stat_button" type="action" <button
name="%(account_invoice_in_invoice_refund_action)d" class="oe_stat_button"
type="action"
name="%(account.action_move_in_invoice_type)d"
context="{'search_default_agreement_id': active_id, 'default_agreement_id': active_id, 'default_partner_id': partner_id}" context="{'search_default_agreement_id': active_id, 'default_agreement_id': active_id, 'default_partner_id': partner_id}"
attrs="{'invisible': [('domain', '!=', 'purchase')]}" attrs="{'invisible': [('domain', '!=', 'purchase')]}"
icon="fa-pencil-square-o"> icon="fa-pencil-square-o"
<field string="Vendor Bills" name="in_invoice_count" widget="statinfo"/> >
<field
string="Vendor Bills"
name="in_invoice_count"
widget="statinfo"
/>
</button> </button>
</div> </div>
</field> </field>
</record> </record>