From 7b8447bb86f6625b4d74bee619934a4c1f380b15 Mon Sep 17 00:00:00 2001 From: Matias Peralta Date: Tue, 17 Dec 2024 11:10:04 -0300 Subject: [PATCH] [ADD] sale_order_type: change of analytical account by project --- sale_order_type/README.rst | 54 +++++++++---------- sale_order_type/__manifest__.py | 2 +- sale_order_type/models/sale.py | 10 ++++ sale_order_type/models/sale_order_type.py | 9 ++-- sale_order_type/tests/test_sale_order_type.py | 5 ++ .../views/sale_order_type_view.xml | 4 +- 6 files changed, 50 insertions(+), 34 deletions(-) diff --git a/sale_order_type/README.rst b/sale_order_type/README.rst index 1fb5854633b..9fd23f192a2 100644 --- a/sale_order_type/README.rst +++ b/sale_order_type/README.rst @@ -85,49 +85,49 @@ Authors Contributors ------------ -- `Vermon `__ +- `Vermon `__ - - Carlos Sánchez Cifuentes + - Carlos Sánchez Cifuentes -- `AvanzOsc `__ +- `AvanzOsc `__ - - Oihane Crucelaegui - - Ana Juaristi - - Daniel Campos - - Ainara Galdona + - Oihane Crucelaegui + - Ana Juaristi + - Daniel Campos + - Ainara Galdona -- `Agile Business Group `__ +- `Agile Business Group `__ - - Lorenzo Battistini + - Lorenzo Battistini -- `Niboo `__ +- `Niboo `__ - - Samuel Lefever - - Pierre Faniel + - Samuel Lefever + - Pierre Faniel -- `Tecnativa `__ +- `Tecnativa `__ - - Pedro M. Baeza - - David Vidal - - Carlos Dauden - - Sergio Teruel + - Pedro M. Baeza + - David Vidal + - Carlos Dauden + - Sergio Teruel -- `Pesol `__ +- `Pesol `__ - - Angel Moya Pardo - - Antonio J Rubio Lorente + - Angel Moya Pardo + - Antonio J Rubio Lorente -- Rattapong Chokmasermkul -- `Druidoo `__ +- Rattapong Chokmasermkul +- `Druidoo `__ - - Iván Todorovich + - Iván Todorovich -- `GSLab.it `__ +- `GSLab.it `__ - - Giovanni Serra + - Giovanni Serra -- Tharathip Chaweewongphan -- Isaac Gallart +- Tharathip Chaweewongphan +- Isaac Gallart Do not contact contributors directly about support or help with technical issues. diff --git a/sale_order_type/__manifest__.py b/sale_order_type/__manifest__.py index 853bc3614ee..54dccfebabf 100644 --- a/sale_order_type/__manifest__.py +++ b/sale_order_type/__manifest__.py @@ -18,7 +18,7 @@ "Odoo Community Association (OCA)", "website": "https://github.com/OCA/sale-workflow", "license": "AGPL-3", - "depends": ["sale_stock", "account", "sale_management"], + "depends": ["sale_stock", "account", "sale_management", "sale_project"], "demo": ["demo/sale_order_demo.xml"], "data": [ "security/ir.model.access.csv", diff --git a/sale_order_type/models/sale.py b/sale_order_type/models/sale.py index 4a949a2a9a3..aa553995920 100644 --- a/sale_order_type/models/sale.py +++ b/sale_order_type/models/sale.py @@ -26,6 +26,9 @@ class SaleOrder(models.Model): compute="_compute_picking_policy", store=True, readonly=False ) incoterm = fields.Many2one(compute="_compute_incoterm", store=True, readonly=False) + project_id = fields.Many2one( + compute="_compute_project_id", store=True, readonly=False + ) @api.model def _default_type_id(self): @@ -124,6 +127,13 @@ def _compute_incoterm(self): order.incoterm = order_type.incoterm_id return res + @api.depends("type_id") + def _compute_project_id(self): + for order in self.filtered("type_id"): + order_type = order.type_id + if order_type.project_id: + order.project_id = order_type.project_id + @api.depends("type_id") def _compute_validity_date(self): res = super()._compute_validity_date() diff --git a/sale_order_type/models/sale_order_type.py b/sale_order_type/models/sale_order_type.py index 4c4e86e6ee8..2f70baf6977 100644 --- a/sale_order_type/models/sale_order_type.py +++ b/sale_order_type/models/sale_order_type.py @@ -52,10 +52,11 @@ class SaleOrderTypology(models.Model): ondelete="restrict", check_company=True, ) - analytic_account_id = fields.Many2one( - comodel_name="account.analytic.account", - string="Analytic account", - check_company=True, + project_id = fields.Many2one( + comodel_name="project.project", + domain=[("allow_billable", "=", True)], + string="Project", + help="Select to define the analytics account (new approach in v18)", ) active = fields.Boolean(default=True) quotation_validity_days = fields.Integer(string="Quotation Validity (Days)") diff --git a/sale_order_type/tests/test_sale_order_type.py b/sale_order_type/tests/test_sale_order_type.py index 9931f712e45..ce104abba20 100644 --- a/sale_order_type/tests/test_sale_order_type.py +++ b/sale_order_type/tests/test_sale_order_type.py @@ -56,6 +56,7 @@ def setUp(self): self.sale_pricelist = self.env["product.pricelist"].create( {"name": "Public Pricelist", "sequence": 1} ) + self.project_id = self.env["project.project"].create({"name": "Project sample"}) self.free_carrier = self.env.ref("account.incoterm_FCA") self.sale_type = self.sale_type_model.create( { @@ -66,6 +67,7 @@ def setUp(self): "picking_policy": "one", "payment_term_id": self.immediate_payment.id, "pricelist_id": self.sale_pricelist.id, + "project_id": self.project_id.id, "incoterm_id": self.free_carrier.id, "quotation_validity_days": 10, } @@ -79,6 +81,7 @@ def setUp(self): "picking_policy": "one", "payment_term_id": self.immediate_payment.id, "pricelist_id": self.sale_pricelist.id, + "project_id": self.project_id.id, "incoterm_id": self.free_carrier.id, } ) @@ -125,6 +128,7 @@ def setUp(self): "picking_policy": "one", "payment_term_id": self.immediate_payment.id, "pricelist_id": self.sale_pricelist.id, + "project_id": self.project_id.id, "incoterm_id": self.free_carrier.id, "route_id": self.sale_route.id, } @@ -158,6 +162,7 @@ def test_sale_order_flow(self): self.assertEqual(order.picking_policy, sale_type.picking_policy) self.assertEqual(order.payment_term_id, sale_type.payment_term_id) self.assertEqual(order.pricelist_id, sale_type.pricelist_id) + self.assertEqual(order.project_id, sale_type.project_id) self.assertEqual(order.incoterm, sale_type.incoterm_id) order.action_confirm() invoice = order._create_invoices() diff --git a/sale_order_type/views/sale_order_type_view.xml b/sale_order_type/views/sale_order_type_view.xml index d2822cc00fd..c4218c2b518 100644 --- a/sale_order_type/views/sale_order_type_view.xml +++ b/sale_order_type/views/sale_order_type_view.xml @@ -39,8 +39,8 @@ />