From 3c56a7777ca0d1d2cbe55990ebc3366793af6559 Mon Sep 17 00:00:00 2001 From: Patrick Wilson <36892066+patrickrwilson@users.noreply.github.com> Date: Mon, 10 May 2021 15:45:18 -0600 Subject: [PATCH] [14.0][MIG] agreement_legal_sale (Version 12.0 to 14.0) [MIG] Prettier [MIG] Tests Pre-Commit --- agreement_legal_sale/README.rst | 8 +-- agreement_legal_sale/__manifest__.py | 36 +++++----- agreement_legal_sale/models/agreement.py | 12 ++-- agreement_legal_sale/models/sale_order.py | 71 ++++++++++--------- .../static/description/index.html | 6 +- agreement_legal_sale/tests/__init__.py | 1 + agreement_legal_sale/tests/test_sale_order.py | 52 ++++++++++++++ agreement_legal_sale/views/agreement.xml | 20 +++--- agreement_legal_sale/views/sale_order.xml | 15 ++-- 9 files changed, 138 insertions(+), 83 deletions(-) create mode 100644 agreement_legal_sale/tests/__init__.py create mode 100644 agreement_legal_sale/tests/test_sale_order.py diff --git a/agreement_legal_sale/README.rst b/agreement_legal_sale/README.rst index fadda0cd3..702c1e024 100644 --- a/agreement_legal_sale/README.rst +++ b/agreement_legal_sale/README.rst @@ -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 `_. 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -126,6 +126,6 @@ Current `maintainers `__: |maintainer-osi-scampbell| |maintainer-max3903| -This module is part of the `OCA/contract `_ project on GitHub. +This module is part of the `OCA/contract `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/agreement_legal_sale/__manifest__.py b/agreement_legal_sale/__manifest__.py index eb40ee121..0f00767d0 100644 --- a/agreement_legal_sale/__manifest__.py +++ b/agreement_legal_sale/__manifest__.py @@ -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", ], } diff --git a/agreement_legal_sale/models/agreement.py b/agreement_legal_sale/models/agreement.py index 47ba502eb..456c03d12 100644 --- a/agreement_legal_sale/models/agreement.py +++ b/agreement_legal_sale/models/agreement.py @@ -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") diff --git a/agreement_legal_sale/models/sale_order.py b/agreement_legal_sale/models/sale_order.py index 76c48eec0..8a3e308bd 100644 --- a/agreement_legal_sale/models/sale_order.py +++ b/agreement_legal_sale/models/sale_order.py @@ -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 diff --git a/agreement_legal_sale/static/description/index.html b/agreement_legal_sale/static/description/index.html index 1aa0ee8a5..e47063650 100644 --- a/agreement_legal_sale/static/description/index.html +++ b/agreement_legal_sale/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/contract Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/contract Translate me on Weblate Try me on Runbot

Odoo Sales App does not support the management of legal content for agreements and contracts. It’s also not integrated with the Agreement App.

This module is for companies that needs their customer to sign an agreement @@ -426,7 +426,7 @@ sections, clauses, recitals and appendices

Bugs are tracked on GitHub 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.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -462,7 +462,7 @@ mission is to support the collaborative development of Odoo features and promote its widespread use.

Current maintainers:

osi-scampbell max3903

-

This module is part of the OCA/contract project on GitHub.

+

This module is part of the OCA/contract project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/agreement_legal_sale/tests/__init__.py b/agreement_legal_sale/tests/__init__.py new file mode 100644 index 000000000..6f699d0d8 --- /dev/null +++ b/agreement_legal_sale/tests/__init__.py @@ -0,0 +1 @@ +from . import test_sale_order diff --git a/agreement_legal_sale/tests/test_sale_order.py b/agreement_legal_sale/tests/test_sale_order.py new file mode 100644 index 000000000..0727c12c4 --- /dev/null +++ b/agreement_legal_sale/tests/test_sale_order.py @@ -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, + ) diff --git a/agreement_legal_sale/views/agreement.xml b/agreement_legal_sale/views/agreement.xml index dffaee978..8c4be1ef0 100644 --- a/agreement_legal_sale/views/agreement.xml +++ b/agreement_legal_sale/views/agreement.xml @@ -1,29 +1,31 @@ - + - agreement.form.view agreement - + - - + + - + - + diff --git a/agreement_legal_sale/views/sale_order.xml b/agreement_legal_sale/views/sale_order.xml index 8a077c3db..c6bc21c2c 100644 --- a/agreement_legal_sale/views/sale_order.xml +++ b/agreement_legal_sale/views/sale_order.xml @@ -1,20 +1,21 @@ - + - sale.order.agreement.form.view sale.order - + - - {'invisible': [('agreement_id', '=', False)]} + + {'invisible': [('agreement_id', '=', False)]} - +