mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[14.0][MIG] agreement_legal_sale (Version 12.0 to 14.0)
[MIG] Prettier [MIG] Tests Pre-Commit
This commit is contained in:
@@ -14,13 +14,13 @@ Agreement Legal Sale
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |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
|
||||
.. |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
|
||||
:alt: Translate me on Weblate
|
||||
.. |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
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
@@ -75,7 +75,7 @@ Bug Tracker
|
||||
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.
|
||||
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.
|
||||
|
||||
@@ -126,6 +126,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
|
||||
|
||||
|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.
|
||||
|
||||
@@ -2,26 +2,22 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Agreement Legal Sale',
|
||||
'summary': 'Create an agreement when the sale order is confirmed',
|
||||
'version': '12.0.2.0.0',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'Open Source Integrators, Odoo Community Association (OCA)',
|
||||
'category': 'Agreement',
|
||||
'website': 'https://github.com/OCA/contract',
|
||||
'depends': [
|
||||
'agreement_legal',
|
||||
'agreement_sale',
|
||||
'agreement_serviceprofile'
|
||||
"name": "Agreement Legal Sale",
|
||||
"summary": "Create an agreement when the sale order is confirmed",
|
||||
"version": "14.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Open Source Integrators, Odoo Community Association (OCA)",
|
||||
"category": "Agreement",
|
||||
"website": "https://github.com/OCA/contract",
|
||||
"depends": ["agreement_legal", "agreement_sale", "agreement_serviceprofile"],
|
||||
"data": [
|
||||
"views/agreement.xml",
|
||||
"views/sale_order.xml",
|
||||
],
|
||||
'data': [
|
||||
'views/agreement.xml',
|
||||
'views/sale_order.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'development_status': 'Beta',
|
||||
'maintainers': [
|
||||
'osi-scampbell',
|
||||
'max3903',
|
||||
"installable": True,
|
||||
"development_status": "Beta",
|
||||
"maintainers": [
|
||||
"osi-scampbell",
|
||||
"max3903",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -5,17 +5,15 @@ from odoo import fields, models
|
||||
|
||||
|
||||
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(
|
||||
'account.analytic.account',
|
||||
'Analytic Account',
|
||||
copy=False)
|
||||
"account.analytic.account", "Analytic Account", copy=False
|
||||
)
|
||||
|
||||
|
||||
class AgreementLine(models.Model):
|
||||
_inherit = "agreement.line"
|
||||
|
||||
sale_line_id = fields.Many2one('sale.order.line',
|
||||
string='Sales Order Line')
|
||||
sale_line_id = fields.Many2one("sale.order.line", string="Sales Order Line")
|
||||
|
||||
@@ -1,63 +1,65 @@
|
||||
# Copyright (C) 2019 - TODAY, Open Source Integrators
|
||||
# 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):
|
||||
_inherit = 'sale.order'
|
||||
_inherit = "sale.order"
|
||||
|
||||
agreement_template_id = fields.Many2one(
|
||||
'agreement',
|
||||
string="Agreement Template",
|
||||
domain="[('is_template', '=', True)]")
|
||||
"agreement", string="Agreement Template", domain="[('is_template', '=', True)]"
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def _action_confirm(self):
|
||||
res = super(SaleOrder, self)._action_confirm()
|
||||
for order in self:
|
||||
if order.agreement_template_id:
|
||||
order.agreement_id = order.\
|
||||
agreement_template_id.copy(default={
|
||||
'name': order.name,
|
||||
'code': order.name,
|
||||
'is_template': False,
|
||||
'sale_id': order.id,
|
||||
'partner_id': order.partner_id.id,
|
||||
'analytic_account_id': order.analytic_account_id and
|
||||
order.analytic_account_id.id or False,
|
||||
})
|
||||
order.agreement_id = order.agreement_template_id.copy(
|
||||
default={
|
||||
"name": order.name,
|
||||
"code": order.name,
|
||||
"is_template": False,
|
||||
"sale_id": order.id,
|
||||
"partner_id": order.partner_id.id,
|
||||
"analytic_account_id": order.analytic_account_id
|
||||
and order.analytic_account_id.id
|
||||
or False,
|
||||
}
|
||||
)
|
||||
for line in order.order_line:
|
||||
# Create agreement line
|
||||
self.env['agreement.line'].\
|
||||
create(self._get_agreement_line_vals(line))
|
||||
self.env["agreement.line"].create(
|
||||
self._get_agreement_line_vals(line)
|
||||
)
|
||||
# Create SP's based on product_id config
|
||||
if line.product_id.is_serviceprofile:
|
||||
self.create_sp_qty(line, order)
|
||||
return res
|
||||
|
||||
def create_sp_qty(self, line, order):
|
||||
""" Create line.product_uom_qty SP's """
|
||||
"""Create line.product_uom_qty SP's"""
|
||||
if line.product_id.product_tmpl_id.is_serviceprofile:
|
||||
for i in range(1, int(line.product_uom_qty)+1):
|
||||
self.env['agreement.serviceprofile'].\
|
||||
create(self._get_sp_vals(line, order, i))
|
||||
for i in range(1, int(line.product_uom_qty) + 1):
|
||||
self.env["agreement.serviceprofile"].create(
|
||||
self._get_sp_vals(line, order, i)
|
||||
)
|
||||
|
||||
def _get_agreement_line_vals(self, line):
|
||||
return {
|
||||
'product_id': line.product_id.id,
|
||||
'name': line.name,
|
||||
'agreement_id': line.order_id.agreement_id.id,
|
||||
'qty': line.product_uom_qty,
|
||||
'sale_line_id': line.id,
|
||||
'uom_id': line.product_uom.id
|
||||
"product_id": line.product_id.id,
|
||||
"name": line.name,
|
||||
"agreement_id": line.order_id.agreement_id.id,
|
||||
"qty": line.product_uom_qty,
|
||||
"sale_line_id": line.id,
|
||||
"uom_id": line.product_uom.id,
|
||||
}
|
||||
|
||||
def _get_sp_vals(self, line, order, i):
|
||||
return {
|
||||
'name': line.name + ' ' + str(i),
|
||||
'product_id': line.product_id.product_tmpl_id.id,
|
||||
'agreement_id': order.agreement_id.id,
|
||||
"name": line.name + " " + str(i),
|
||||
"product_id": line.product_id.product_tmpl_id.id,
|
||||
"agreement_id": order.agreement_id.id,
|
||||
}
|
||||
|
||||
def action_confirm(self):
|
||||
@@ -70,7 +72,10 @@ class SaleOrder(models.Model):
|
||||
res = super(SaleOrder, self).action_confirm()
|
||||
for order in self:
|
||||
agreement = order.agreement_id
|
||||
if (order.analytic_account_id and agreement and
|
||||
not agreement.analytic_account_id):
|
||||
if (
|
||||
order.analytic_account_id
|
||||
and agreement
|
||||
and not agreement.analytic_account_id
|
||||
):
|
||||
agreement.analytic_account_id = order.analytic_account_id
|
||||
return res
|
||||
|
||||
@@ -367,7 +367,7 @@ ul.auto-toc {
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! 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
|
||||
and contracts. It’s also not integrated with the Agreement App.</p>
|
||||
<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>.
|
||||
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
|
||||
<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>
|
||||
</div>
|
||||
<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>
|
||||
<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>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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
1
agreement_legal_sale/tests/__init__.py
Normal file
1
agreement_legal_sale/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_sale_order
|
||||
52
agreement_legal_sale/tests/test_sale_order.py
Normal file
52
agreement_legal_sale/tests/test_sale_order.py
Normal 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,
|
||||
)
|
||||
@@ -1,29 +1,31 @@
|
||||
<?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). -->
|
||||
<odoo>
|
||||
|
||||
<!-- Agreement Form View -->
|
||||
<record id="agreement_sale_form_view" model="ir.ui.view">
|
||||
<field name="name">agreement.form.view</field>
|
||||
<field name="model">agreement</field>
|
||||
<field name="inherit_id"
|
||||
ref="agreement_legal.partner_agreement_form_view"/>
|
||||
<field name="inherit_id" ref="agreement_legal.partner_agreement_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<page name="signature" position="after">
|
||||
<page name="sales" string="Sales">
|
||||
<group>
|
||||
<group id="sale_left">
|
||||
<field name="sale_id" readonly="1"/>
|
||||
<field name="analytic_account_id"/>
|
||||
<field name="sale_id" readonly="1" />
|
||||
<field name="analytic_account_id" />
|
||||
</group>
|
||||
<group id="sale_right"/>
|
||||
<group id="sale_right" />
|
||||
</group>
|
||||
</page>
|
||||
</page>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="agreement.agreement_menu" action="agreement.agreement_action" sequence="100"/>
|
||||
<menuitem
|
||||
id="agreement.agreement_menu"
|
||||
action="agreement.agreement_action"
|
||||
sequence="100"
|
||||
/>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
<?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). -->
|
||||
<odoo>
|
||||
|
||||
<!-- Agreement Form View -->
|
||||
<record id="sale_order_agreement_form_view" model="ir.ui.view">
|
||||
<field name="name">sale.order.agreement.form.view</field>
|
||||
<field name="model">sale.order</field>
|
||||
<field name="inherit_id" ref="agreement_sale.sale_order_agreement_form_view"/>
|
||||
<field name="inherit_id" ref="agreement_sale.sale_order_agreement_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="agreement_id" position="attributes">
|
||||
<attribute name="readonly" eval='1'/>
|
||||
<attribute name="attrs">{'invisible': [('agreement_id', '=', False)]}</attribute>
|
||||
<attribute name="readonly" eval='1' />
|
||||
<attribute
|
||||
name="attrs"
|
||||
>{'invisible': [('agreement_id', '=', False)]}</attribute>
|
||||
</field>
|
||||
<field name="partner_id" position="after">
|
||||
<field name="agreement_template_id"/>
|
||||
<field name="agreement_template_id" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user