From 51e38e1a744517f661176056a2cfe702995428d5 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Mon, 27 Nov 2023 11:38:03 +0100 Subject: [PATCH] =?UTF-8?q?wip=20on=20finit=20ce=20projet,=20l=C3=A0=20!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/joint_buying_transport_request.py | 1 + joint_buying_base/tests/__init__.py | 2 + joint_buying_base/tests/test_abstract.py | 8 ++++ .../tests/test_company_2_partner.py | 1 - .../tests/test_joint_buying_mixin.py | 1 - .../test_joint_buying_transport_request.py | 41 +++++++++++++++++ .../test_joint_buying_wizard_find_route.py | 3 -- .../tests/test_partner_global_local.py | 5 -- joint_buying_product/demo/product_product.xml | 2 + .../models/joint_buying_purchase_order.py | 2 +- .../view_joint_buying_transport_request.xml | 8 ++-- joint_buying_sale/__manifest__.py | 7 ++- .../demo/joint_buying_transport_request.xml | 16 +++++++ joint_buying_sale/demo/sale_order.xml | 35 +++++++++++++- .../models/joint_buying_transport_request.py | 46 +++++++++++++++++++ joint_buying_sale/models/sale_order.py | 15 +++--- joint_buying_sale/views/view_sale_order.xml | 23 ++++------ ..._buying_create_transport_request_wizard.py | 8 ++-- 18 files changed, 184 insertions(+), 40 deletions(-) create mode 100644 joint_buying_base/tests/test_joint_buying_transport_request.py create mode 100644 joint_buying_sale/demo/joint_buying_transport_request.xml diff --git a/joint_buying_base/models/joint_buying_transport_request.py b/joint_buying_base/models/joint_buying_transport_request.py index 04ed7ce0..8a60bf41 100644 --- a/joint_buying_base/models/joint_buying_transport_request.py +++ b/joint_buying_base/models/joint_buying_transport_request.py @@ -88,6 +88,7 @@ class JointBuyingTransportRequest(models.Model): compute="_compute_weight", store=True, digits=dp.get_precision("Stock Weight"), + compute_sudo=True, ) line_ids = fields.One2many( diff --git a/joint_buying_base/tests/__init__.py b/joint_buying_base/tests/__init__.py index afe28540..3341632f 100644 --- a/joint_buying_base/tests/__init__.py +++ b/joint_buying_base/tests/__init__.py @@ -7,3 +7,5 @@ from . import test_joint_buying_wizard_find_route from . import test_tour from . import test_tour_report + +from . import test_joint_buying_transport_request diff --git a/joint_buying_base/tests/test_abstract.py b/joint_buying_base/tests/test_abstract.py index 9d67b1a6..e94eb8a3 100644 --- a/joint_buying_base/tests/test_abstract.py +++ b/joint_buying_base/tests/test_abstract.py @@ -14,6 +14,14 @@ def setUp(self): mail_create_nosubscribe=True ) + self.user_3PP = self.env.ref("joint_buying_base.user_joint_buying_user_3PP") + + self.company_3PP = self.env.ref("joint_buying_base.company_3PP") + self.company_CDA = self.env.ref("joint_buying_base.company_CDA") + self.company_CHE = self.env.ref("joint_buying_base.company_CHE") + self.company_ELD = self.env.ref("joint_buying_base.company_ELD") + self.company_VEV = self.env.ref("joint_buying_base.company_VEV") + # Custom Functions def _create_supplier(self, user=False, extra_vals=False): if not user: diff --git a/joint_buying_base/tests/test_company_2_partner.py b/joint_buying_base/tests/test_company_2_partner.py index c506daf4..50dff2ee 100644 --- a/joint_buying_base/tests/test_company_2_partner.py +++ b/joint_buying_base/tests/test_company_2_partner.py @@ -12,7 +12,6 @@ class TestModule(TestAbstract): def setUp(self): super().setUp() - self.company_3PP = self.env.ref("joint_buying_base.company_3PP") self.ResCompany = self.env["res.company"] self.suffixParameter = self.env.ref("joint_buying_base.parameter_group_name") diff --git a/joint_buying_base/tests/test_joint_buying_mixin.py b/joint_buying_base/tests/test_joint_buying_mixin.py index f2e5ef61..8c8d8838 100644 --- a/joint_buying_base/tests/test_joint_buying_mixin.py +++ b/joint_buying_base/tests/test_joint_buying_mixin.py @@ -11,7 +11,6 @@ class TestModule(TestAbstract): def setUp(self): super().setUp() - self.user_3PP = self.env.ref("joint_buying_base.user_joint_buying_user_3PP") self.joint_buying_supplier = self.env.ref( "joint_buying_base.supplier_fumet_dombes" ) diff --git a/joint_buying_base/tests/test_joint_buying_transport_request.py b/joint_buying_base/tests/test_joint_buying_transport_request.py new file mode 100644 index 00000000..2218f431 --- /dev/null +++ b/joint_buying_base/tests/test_joint_buying_transport_request.py @@ -0,0 +1,41 @@ +# Copyright (C) 2021 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from datetime import datetime + +from odoo.tests import tagged + +from .test_abstract import TestAbstract + + +@tagged("post_install", "-at_install") +class TestJointBuyingTransportRequest(TestAbstract): + def setUp(self): + super().setUp() + self.TransportRequest = self.env["joint.buying.transport.request"] + + def test_create_transport_request_manual(self): + request = self.TransportRequest.create( + { + "manual_origin_partner_id": self.company_CDA.joint_buying_partner_id.id, + "manual_destination_partner_id": self.company_CHE.joint_buying_partner_id.id, + "manual_description": "manual_description", + "manual_start_date": datetime.today(), + "manual_amount_untaxed": 999, + "manual_total_weight": 111, + } + ) + + # Check can change values + self.assertTrue(request.can_change_date) + self.assertTrue(request.can_change_extra_data) + self.assertTrue(request.can_change_partners) + + # Check computation + request.manual_description = "bob" + self.assertEqual(request.description, "

bob

") + request.manual_amount_untaxed = 888 + self.assertEqual(request.amount_untaxed, 888) + request.manual_total_weight = 222 + self.assertEqual(request.total_weight, 222) diff --git a/joint_buying_base/tests/test_joint_buying_wizard_find_route.py b/joint_buying_base/tests/test_joint_buying_wizard_find_route.py index 5f4be7e2..d20a305a 100644 --- a/joint_buying_base/tests/test_joint_buying_wizard_find_route.py +++ b/joint_buying_base/tests/test_joint_buying_wizard_find_route.py @@ -10,9 +10,6 @@ @tagged("post_install", "-at_install", "find_route") class TestJointBuyingWizardFindRoute(TestAbstract): - def setUp(self): - super().setUp() - def test_20_transport_request_vev_cda_week_1(self): """simplest case: direct route""" self._verify_tour_lines_computation( diff --git a/joint_buying_base/tests/test_partner_global_local.py b/joint_buying_base/tests/test_partner_global_local.py index 7bb89788..ea940600 100644 --- a/joint_buying_base/tests/test_partner_global_local.py +++ b/joint_buying_base/tests/test_partner_global_local.py @@ -10,11 +10,6 @@ @tagged("post_install", "-at_install") class TestModule(TestAbstract): - def setUp(self): - super().setUp() - self.company_ELD = self.env.ref("joint_buying_base.company_ELD") - self.company_CHE = self.env.ref("joint_buying_base.company_CHE") - self.company_3PP = self.env.ref("joint_buying_base.company_3PP") # Test Section def test_601_double_link_supplier_to_joint_buying_partner(self): diff --git a/joint_buying_product/demo/product_product.xml b/joint_buying_product/demo/product_product.xml index d169da65..e8ee2cea 100644 --- a/joint_buying_product/demo/product_product.xml +++ b/joint_buying_product/demo/product_product.xml @@ -133,6 +133,7 @@ Orangette Sachet 200gr 12 + 0.210 @@ -142,6 +143,7 @@ Gingembrette Sachet 200gr 10 + 0.210 diff --git a/joint_buying_product/models/joint_buying_purchase_order.py b/joint_buying_product/models/joint_buying_purchase_order.py index 7249a6f8..940842ed 100644 --- a/joint_buying_product/models/joint_buying_purchase_order.py +++ b/joint_buying_product/models/joint_buying_purchase_order.py @@ -403,7 +403,7 @@ def correct_purchase_state(self): @api.multi def button_see_request(self): self.ensure_one() - xml_action = "joint_buying_product.action_joint_buying_transport_request" + xml_action = "joint_buying_base.action_joint_buying_transport_request" xml_view = "joint_buying_base.view_joint_buying_transport_request_form" action = self.env.ref(xml_action).read()[0] action["views"] = [(self.env.ref(xml_view).id, "form")] diff --git a/joint_buying_product/views/view_joint_buying_transport_request.xml b/joint_buying_product/views/view_joint_buying_transport_request.xml index e3f37ccf..2d5204ef 100644 --- a/joint_buying_product/views/view_joint_buying_transport_request.xml +++ b/joint_buying_product/views/view_joint_buying_transport_request.xml @@ -10,9 +10,11 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). joint.buying.transport.request - - - + + + + + diff --git a/joint_buying_sale/__manifest__.py b/joint_buying_sale/__manifest__.py index 2d3b15fc..4abc4c85 100644 --- a/joint_buying_sale/__manifest__.py +++ b/joint_buying_sale/__manifest__.py @@ -10,6 +10,8 @@ "license": "AGPL-3", "depends": [ "sale", + # OCA + "sale_order_weight", # GRAP "joint_buying_product", ], @@ -21,7 +23,10 @@ "views/view_joint_buying_transport_request.xml", "views/view_sale_order.xml", ], - "demo": ["demo/sale_order.xml"], + "demo": [ + "demo/sale_order.xml", + "demo/joint_buying_transport_request.xml", + ], "installable": True, "auto_install": True, } diff --git a/joint_buying_sale/demo/joint_buying_transport_request.xml b/joint_buying_sale/demo/joint_buying_transport_request.xml new file mode 100644 index 00000000..21884e5b --- /dev/null +++ b/joint_buying_sale/demo/joint_buying_transport_request.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + diff --git a/joint_buying_sale/demo/sale_order.xml b/joint_buying_sale/demo/sale_order.xml index 9f55db2f..ebbc8d6a 100644 --- a/joint_buying_sale/demo/sale_order.xml +++ b/joint_buying_sale/demo/sale_order.xml @@ -6,6 +6,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> + @@ -17,7 +18,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - + [ELD-ORANGETTE] Orangette Sachet 200gr @@ -26,7 +27,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). 15.00 - + [ELD-GINGEMBRETTE] Gingembrette Sachet 200gr @@ -35,4 +36,34 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). 12.00 + + + + + + + + + + + + + + + [ELD-ORANGETTE] Orangette Sachet 200gr + + 20 + + 15.00 + + + + + [ELD-GINGEMBRETTE] Gingembrette Sachet 200gr + + 30 + + 12.00 + + diff --git a/joint_buying_sale/models/joint_buying_transport_request.py b/joint_buying_sale/models/joint_buying_transport_request.py index 2374d562..01083b59 100644 --- a/joint_buying_sale/models/joint_buying_transport_request.py +++ b/joint_buying_sale/models/joint_buying_transport_request.py @@ -13,4 +13,50 @@ class JointBuyingTransportRequest(models.Model): readonly=True, help="Sale order in the local database of the" " company that requires transport.", + ondelete="cascade", ) + + def _get_depends_amount_untaxed(self): + res = super()._get_depends_amount_untaxed() + res.append("sale_order_id.amount_untaxed") + return res + + def _get_depends_total_weight(self): + res = super()._get_depends_total_weight() + res.append("sale_order_id.total_ordered_weight") + return res + + def _get_depends_description(self): + res = super()._get_depends_description() + res += [ + "sale_order_id.order_line.product_id", + "sale_order_id.order_line.product_uom_qty", + "sale_order_id.order_line.product_uom.name", + ] + return res + + def _compute_amount_untaxed(self): + super( + JointBuyingTransportRequest, self.filtered(lambda x: not x.sale_order_id) + )._compute_amount_untaxed() + + for request in self.filtered(lambda x: x.sale_order_id): + request.amount_untaxed = request.sale_order_id.amount_untaxed + + def _compute_total_weight(self): + super( + JointBuyingTransportRequest, self.filtered(lambda x: not x.sale_order_id) + )._compute_total_weight() + + for request in self.filtered(lambda x: x.sale_order_id): + request.total_weight = request.sale_order_id.total_ordered_weight + + def _compute_can_change(self): + super( + JointBuyingTransportRequest, self.filtered(lambda x: not x.sale_order_id) + )._compute_can_change() + + for request in self.filtered(lambda x: x.sale_order_id): + request.can_change_date = True + request.can_change_extra_data = False + request.can_change_partners = True diff --git a/joint_buying_sale/models/sale_order.py b/joint_buying_sale/models/sale_order.py index 8b3cfbad..8a93bdff 100644 --- a/joint_buying_sale/models/sale_order.py +++ b/joint_buying_sale/models/sale_order.py @@ -8,14 +8,13 @@ class SaleOrder(models.Model): _inherit = "sale.order" - joint_buying_has_transport_request = fields.Boolean( - compute="_compute_joint_buying_has_transport_request", - store=False, - help="Technical field, used to know if the sale order" - " has a related joint buying transport request created.", + joint_buying_transport_request_id = fields.Many2one( + comodel_name="joint.buying.transport.request", + compute="_compute_joint_buying_transport_request", ) joint_buying_transport_request_ids = fields.One2many( + string="Joint Buying Transport Requests", comodel_name="joint.buying.transport.request", inverse_name="sale_order_id", help="Technical field, used to know if the sale order" @@ -23,8 +22,10 @@ class SaleOrder(models.Model): " It can contain only 0 or one transport request.", ) - def _compute_joint_buying_has_transport_request(self): + def _compute_joint_buying_transport_request(self): for order in self: - order.joint_buying_has_transport_request = len( + order.joint_buying_transport_request_id = ( order.joint_buying_transport_request_ids + and order.joint_buying_transport_request_ids[0] + or False ) diff --git a/joint_buying_sale/views/view_sale_order.xml b/joint_buying_sale/views/view_sale_order.xml index 252927a7..0e9ab3e2 100644 --- a/joint_buying_sale/views/view_sale_order.xml +++ b/joint_buying_sale/views/view_sale_order.xml @@ -10,22 +10,19 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). sale.order - - - +