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

[MIG] Prettier

[MIG] Tests

Pre-Commit
This commit is contained in:
Patrick Wilson
2021-05-10 15:45:18 -06:00
parent 1b18d132a3
commit 3c56a7777c
9 changed files with 138 additions and 83 deletions

View File

@@ -14,13 +14,13 @@ Agreement Legal Sale
: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_legal_sale :target: https://github.com/OCA/contract/tree/14.0/agreement_legal_sale
: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_legal_sale :target: https://translation.odoo-community.org/projects/contract-12-0/contract-12-0-agreement_legal_sale
: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|
@@ -75,7 +75,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/contract/issues>`_.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/contract/issues/new?body=module:%20agreement_legal_sale%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/contract/issues/new?body=module:%20agreement_legal_sale%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@@ -126,6 +126,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-osi-scampbell| |maintainer-max3903| |maintainer-osi-scampbell| |maintainer-max3903|
This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/12.0/agreement_legal_sale>`_ project on GitHub. This module is part of the `OCA/contract <https://github.com/OCA/contract/tree/14.0/agreement_legal_sale>`_ 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

@@ -2,26 +2,22 @@
# 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 Legal Sale', "name": "Agreement Legal Sale",
'summary': 'Create an agreement when the sale order is confirmed', "summary": "Create an agreement when the sale order is confirmed",
'version': '12.0.2.0.0', "version": "14.0.1.0.0",
'license': 'AGPL-3', "license": "AGPL-3",
'author': 'Open Source Integrators, Odoo Community Association (OCA)', "author": "Open Source Integrators, Odoo Community Association (OCA)",
'category': 'Agreement', "category": "Agreement",
'website': 'https://github.com/OCA/contract', "website": "https://github.com/OCA/contract",
'depends': [ "depends": ["agreement_legal", "agreement_sale", "agreement_serviceprofile"],
'agreement_legal', "data": [
'agreement_sale', "views/agreement.xml",
'agreement_serviceprofile' "views/sale_order.xml",
], ],
'data': [ "installable": True,
'views/agreement.xml', "development_status": "Beta",
'views/sale_order.xml', "maintainers": [
], "osi-scampbell",
'installable': True, "max3903",
'development_status': 'Beta',
'maintainers': [
'osi-scampbell',
'max3903',
], ],
} }

View File

@@ -5,17 +5,15 @@ from odoo import fields, models
class Agreement(models.Model): class Agreement(models.Model):
_inherit = 'agreement' _inherit = "agreement"
sale_id = fields.Many2one('sale.order', string='Sales Order') sale_id = fields.Many2one("sale.order", string="Sales Order")
analytic_account_id = fields.Many2one( analytic_account_id = fields.Many2one(
'account.analytic.account', "account.analytic.account", "Analytic Account", copy=False
'Analytic Account', )
copy=False)
class AgreementLine(models.Model): class AgreementLine(models.Model):
_inherit = "agreement.line" _inherit = "agreement.line"
sale_line_id = fields.Many2one('sale.order.line', sale_line_id = fields.Many2one("sale.order.line", string="Sales Order Line")
string='Sales Order Line')

View File

@@ -1,36 +1,37 @@
# Copyright (C) 2019 - TODAY, Open Source Integrators # Copyright (C) 2019 - TODAY, Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models from odoo import fields, models
class SaleOrder(models.Model): class SaleOrder(models.Model):
_inherit = 'sale.order' _inherit = "sale.order"
agreement_template_id = fields.Many2one( agreement_template_id = fields.Many2one(
'agreement', "agreement", string="Agreement Template", domain="[('is_template', '=', True)]"
string="Agreement Template", )
domain="[('is_template', '=', True)]")
@api.multi
def _action_confirm(self): def _action_confirm(self):
res = super(SaleOrder, self)._action_confirm() res = super(SaleOrder, self)._action_confirm()
for order in self: for order in self:
if order.agreement_template_id: if order.agreement_template_id:
order.agreement_id = order.\ order.agreement_id = order.agreement_template_id.copy(
agreement_template_id.copy(default={ default={
'name': order.name, "name": order.name,
'code': order.name, "code": order.name,
'is_template': False, "is_template": False,
'sale_id': order.id, "sale_id": order.id,
'partner_id': order.partner_id.id, "partner_id": order.partner_id.id,
'analytic_account_id': order.analytic_account_id and "analytic_account_id": order.analytic_account_id
order.analytic_account_id.id or False, and order.analytic_account_id.id
}) or False,
}
)
for line in order.order_line: for line in order.order_line:
# Create agreement line # Create agreement line
self.env['agreement.line'].\ self.env["agreement.line"].create(
create(self._get_agreement_line_vals(line)) self._get_agreement_line_vals(line)
)
# Create SP's based on product_id config # Create SP's based on product_id config
if line.product_id.is_serviceprofile: if line.product_id.is_serviceprofile:
self.create_sp_qty(line, order) self.create_sp_qty(line, order)
@@ -40,24 +41,25 @@ class SaleOrder(models.Model):
"""Create line.product_uom_qty SP's""" """Create line.product_uom_qty SP's"""
if line.product_id.product_tmpl_id.is_serviceprofile: if line.product_id.product_tmpl_id.is_serviceprofile:
for i in range(1, int(line.product_uom_qty) + 1): for i in range(1, int(line.product_uom_qty) + 1):
self.env['agreement.serviceprofile'].\ self.env["agreement.serviceprofile"].create(
create(self._get_sp_vals(line, order, i)) self._get_sp_vals(line, order, i)
)
def _get_agreement_line_vals(self, line): def _get_agreement_line_vals(self, line):
return { return {
'product_id': line.product_id.id, "product_id": line.product_id.id,
'name': line.name, "name": line.name,
'agreement_id': line.order_id.agreement_id.id, "agreement_id": line.order_id.agreement_id.id,
'qty': line.product_uom_qty, "qty": line.product_uom_qty,
'sale_line_id': line.id, "sale_line_id": line.id,
'uom_id': line.product_uom.id "uom_id": line.product_uom.id,
} }
def _get_sp_vals(self, line, order, i): def _get_sp_vals(self, line, order, i):
return { return {
'name': line.name + ' ' + str(i), "name": line.name + " " + str(i),
'product_id': line.product_id.product_tmpl_id.id, "product_id": line.product_id.product_tmpl_id.id,
'agreement_id': order.agreement_id.id, "agreement_id": order.agreement_id.id,
} }
def action_confirm(self): def action_confirm(self):
@@ -70,7 +72,10 @@ class SaleOrder(models.Model):
res = super(SaleOrder, self).action_confirm() res = super(SaleOrder, self).action_confirm()
for order in self: for order in self:
agreement = order.agreement_id agreement = order.agreement_id
if (order.analytic_account_id and agreement and if (
not agreement.analytic_account_id): order.analytic_account_id
and agreement
and not agreement.analytic_account_id
):
agreement.analytic_account_id = order.analytic_account_id agreement.analytic_account_id = order.analytic_account_id
return res return res

View File

@@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/contract/tree/12.0/agreement_legal_sale"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/contract-12-0/contract-12-0-agreement_legal_sale"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/110/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/contract/tree/14.0/agreement_legal_sale"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/contract-12-0/contract-12-0-agreement_legal_sale"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/110/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>Odoo Sales App does not support the management of legal content for agreements <p>Odoo Sales App does not support the management of legal content for agreements
and contracts. Its also not integrated with the Agreement App.</p> and contracts. Its also not integrated with the Agreement App.</p>
<p>This module is for companies that needs their customer to sign an agreement <p>This module is for companies that needs their customer to sign an agreement
@@ -426,7 +426,7 @@ sections, clauses, recitals and appendices</li>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/contract/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/contract/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/contract/issues/new?body=module:%20agreement_legal_sale%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/contract/issues/new?body=module:%20agreement_legal_sale%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@@ -462,7 +462,7 @@ mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p> <p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external" href="https://github.com/osi-scampbell"><img alt="osi-scampbell" src="https://github.com/osi-scampbell.png?size=40px" /></a> <a class="reference external" href="https://github.com/max3903"><img alt="max3903" src="https://github.com/max3903.png?size=40px" /></a></p> <p><a class="reference external" href="https://github.com/osi-scampbell"><img alt="osi-scampbell" src="https://github.com/osi-scampbell.png?size=40px" /></a> <a class="reference external" href="https://github.com/max3903"><img alt="max3903" src="https://github.com/max3903.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/contract/tree/12.0/agreement_legal_sale">OCA/contract</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/contract/tree/14.0/agreement_legal_sale">OCA/contract</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

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

View File

@@ -0,0 +1,52 @@
# Copyright 2021 Ecosoft Co., Ltd (http://ecosoft.co.th)
# Copyright 2021 Sergio Teruel - Tecnativa
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html)
from datetime import timedelta
from odoo import fields
from odoo.tests.common import TransactionCase
class TestSaleOrder(TransactionCase):
def setUp(self):
super().setUp()
self.test_customer = self.env["res.partner"].create({"name": "TestCustomer"})
self.agreement_type = self.env["agreement.type"].create(
{
"name": "Test Agreement Type",
"domain": "sale",
}
)
self.test_agreement_template = self.env["agreement"].create(
{
"name": "TestAgreementTemplate",
"description": "Test Template",
"special_terms": "Test Template",
"is_template": True,
"partner_id": self.test_customer.id,
"start_date": fields.Date.today(),
"end_date": fields.Date.today() + timedelta(days=365),
}
)
self.test_product = self.env["product.product"].create({"name": "TestProduct"})
self.test_sale_order = self.env["sale.order"].create(
{
"partner_id": self.test_customer.id,
"agreement_template_id": self.test_agreement_template.id,
"date_order": fields.Date.today(),
"order_line": [
(0, 0, {"product_id": self.test_product.id, "product_uom_qty": 1.0})
],
}
)
# TEST 01: Test _action_confirm method
def test_action_confirm(self):
sale_order = self.test_sale_order
sale_order._action_confirm()
agreement = self.env["agreement"].search([("sale_id", "=", sale_order.id)])
self.assertEqual(
agreement.sale_id.id,
sale_order.id,
)

View File

@@ -1,14 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Copyright 2019 Open Source Integrators <!-- Copyright 2019 Open Source Integrators
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<!-- Agreement Form View --> <!-- Agreement Form View -->
<record id="agreement_sale_form_view" model="ir.ui.view"> <record id="agreement_sale_form_view" model="ir.ui.view">
<field name="name">agreement.form.view</field> <field name="name">agreement.form.view</field>
<field name="model">agreement</field> <field name="model">agreement</field>
<field name="inherit_id" <field name="inherit_id" ref="agreement_legal.partner_agreement_form_view" />
ref="agreement_legal.partner_agreement_form_view"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<page name="signature" position="after"> <page name="signature" position="after">
<page name="sales" string="Sales"> <page name="sales" string="Sales">
@@ -24,6 +22,10 @@
</field> </field>
</record> </record>
<menuitem id="agreement.agreement_menu" action="agreement.agreement_action" sequence="100"/> <menuitem
id="agreement.agreement_menu"
action="agreement.agreement_action"
sequence="100"
/>
</odoo> </odoo>

View File

@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Copyright 2019 Open Source Integrators <!-- Copyright 2019 Open Source Integrators
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<!-- Agreement Form View --> <!-- Agreement Form View -->
<record id="sale_order_agreement_form_view" model="ir.ui.view"> <record id="sale_order_agreement_form_view" model="ir.ui.view">
@@ -11,7 +10,9 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="agreement_id" position="attributes"> <field name="agreement_id" position="attributes">
<attribute name="readonly" eval='1' /> <attribute name="readonly" eval='1' />
<attribute name="attrs">{'invisible': [('agreement_id', '=', False)]}</attribute> <attribute
name="attrs"
>{'invisible': [('agreement_id', '=', False)]}</attribute>
</field> </field>
<field name="partner_id" position="after"> <field name="partner_id" position="after">
<field name="agreement_template_id" /> <field name="agreement_template_id" />