From b3fd73640706154abf5309fc822151af59a8c106 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Thu, 25 Jan 2024 21:13:56 +0100 Subject: [PATCH 1/4] [REF] joint_buying_product : Allow to set different delivery place than the customer location --- joint_buying_product/__manifest__.py | 2 +- .../joint_buying_purchase_order_grouped.xml | 5 +++ .../migrations/12.0.5.0.0/pre-migration.py | 31 +++++++++++++++++++ .../models/joint_buying_purchase_order.py | 20 +++++++++++- .../models/joint_buying_transport_request.py | 4 +-- .../view_joint_buying_purchase_order.xml | 1 + 6 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 joint_buying_product/migrations/12.0.5.0.0/pre-migration.py diff --git a/joint_buying_product/__manifest__.py b/joint_buying_product/__manifest__.py index 55b68cb3..dea5ae55 100644 --- a/joint_buying_product/__manifest__.py +++ b/joint_buying_product/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Joint Buying - Products", - "version": "12.0.4.0.2", + "version": "12.0.5.0.0", "category": "GRAP - Logistics", "author": "GRAP", "website": "https://github.com/grap/odoo-addons-logistics", diff --git a/joint_buying_product/demo/joint_buying_purchase_order_grouped.xml b/joint_buying_product/demo/joint_buying_purchase_order_grouped.xml index de4de3ca..64e7876e 100644 --- a/joint_buying_product/demo/joint_buying_purchase_order_grouped.xml +++ b/joint_buying_product/demo/joint_buying_purchase_order_grouped.xml @@ -22,6 +22,7 @@ + @@ -56,6 +57,7 @@ + @@ -89,6 +91,7 @@ + @@ -122,6 +125,7 @@ + @@ -155,6 +159,7 @@ + diff --git a/joint_buying_product/migrations/12.0.5.0.0/pre-migration.py b/joint_buying_product/migrations/12.0.5.0.0/pre-migration.py new file mode 100644 index 00000000..75461826 --- /dev/null +++ b/joint_buying_product/migrations/12.0.5.0.0/pre-migration.py @@ -0,0 +1,31 @@ +# Copyright (C) 2024-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). + +import logging + +from openupgradelib import openupgrade + +_logger = logging.getLogger(__name__) + + +@openupgrade.migrate() +def migrate(env, version): + # Configure Correctly new 'Delivery Place' Field + if not openupgrade.column_exists( + env.cr, "joint_buying_purchase_order", "delivery_partner_id" + ): + openupgrade.logged_query( + env.cr, + """ + ALTER TABLE joint_buying_purchase_order + ADD COLUMN delivery_partner_id int; + """, + ) + openupgrade.logged_query( + env.cr, + """ + UPDATE joint_buying_purchase_order jbpo + SET delivery_partner_id = jbpo.customer_id; + """, + ) diff --git a/joint_buying_product/models/joint_buying_purchase_order.py b/joint_buying_product/models/joint_buying_purchase_order.py index e16393e5..93da5674 100644 --- a/joint_buying_product/models/joint_buying_purchase_order.py +++ b/joint_buying_product/models/joint_buying_purchase_order.py @@ -87,6 +87,20 @@ class JointBuyingPurchaseOrder(models.Model): context=_JOINT_BUYING_PARTNER_CONTEXT, ) + delivery_partner_id = fields.Many2one( + comodel_name="res.partner", + string="Delivery Place", + required=True, + track_visibility=True, + context=_JOINT_BUYING_PARTNER_CONTEXT, + help="the place where the goods are" + " to be delivered. Defined by default" + " as the customer's address," + " the location may be different in some cases," + " if the customer collects the goods" + " from another location.", + ) + state = fields.Selection( related="grouped_order_id.state", string="State", store=True ) @@ -316,7 +330,11 @@ def _compute_total_weight(self): @api.model def _prepare_order_vals(self, supplier, customer, categories): OrderLine = self.env["joint.buying.purchase.order.line"] - res = {"customer_id": customer.id, "line_ids": []} + res = { + "customer_id": customer.id, + "delivery_partner_id": customer.id, + "line_ids": [], + } for product in supplier._get_joint_buying_products(categories): vals = OrderLine._prepare_line_vals(product) res["line_ids"].append((0, 0, vals)) diff --git a/joint_buying_product/models/joint_buying_transport_request.py b/joint_buying_product/models/joint_buying_transport_request.py index a2ee3cd7..093ffcb0 100644 --- a/joint_buying_product/models/joint_buying_transport_request.py +++ b/joint_buying_product/models/joint_buying_transport_request.py @@ -41,7 +41,7 @@ def _get_depends_start_partner_id(self): def _get_depends_arrival_partner_id(self): res = super()._get_depends_arrival_partner_id() - res.append("order_id.deposit_partner_id") + res.append("order_id.delivery_partner_id") return res def _get_depends_amount_untaxed(self): @@ -106,7 +106,7 @@ def _compute_arrival_partner_id(self): )._compute_arrival_partner_id() for request in self.filtered(lambda x: x.order_id): - request.arrival_partner_id = request.order_id.customer_id + request.arrival_partner_id = request.order_id.delivery_partner_id def _compute_amount_untaxed(self): super( diff --git a/joint_buying_product/views/view_joint_buying_purchase_order.xml b/joint_buying_product/views/view_joint_buying_purchase_order.xml index a8970ccc..e3c912ef 100644 --- a/joint_buying_product/views/view_joint_buying_purchase_order.xml +++ b/joint_buying_product/views/view_joint_buying_purchase_order.xml @@ -104,6 +104,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +