diff --git a/purchase_order_shipping_method/__manifest__.py b/purchase_order_shipping_method/__manifest__.py index 4d9fc63bd3..2d8af426d4 100644 --- a/purchase_order_shipping_method/__manifest__.py +++ b/purchase_order_shipping_method/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Purchase Order Shipping Method", - "version": "14.0.1.0.0", + "version": "14.0.1.1.0", "category": "Sales", "license": "AGPL-3", "author": "AvanzOSC", @@ -25,4 +25,5 @@ "views/transport_carrier_lines_to_invoice_view.xml", ], "installable": True, + "pre_init_hook": "pre_init_hook", } diff --git a/purchase_order_shipping_method/migrations/14.0.1.1.0/pre-migration.py b/purchase_order_shipping_method/migrations/14.0.1.1.0/pre-migration.py new file mode 100644 index 0000000000..614d357aaf --- /dev/null +++ b/purchase_order_shipping_method/migrations/14.0.1.1.0/pre-migration.py @@ -0,0 +1,27 @@ +# Copyright 2024 Berezi Amubieta - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +import logging + +from openupgradelib import openupgrade + +_logger = logging.getLogger(__name__) + + +@openupgrade.migrate() +def migrate(env, version): + cr = env.cr + if not openupgrade.column_exists(cr, "stock_picking", "total_done_qty"): + cr.execute( + """ + ALTER TABLE stock_picking + ADD COLUMN total_done_qty float; + """ + ) + cr.execute( + """ + UPDATE stock_picking + SET total_done_qty = (SELECT SUM(qty_done) + FROM stock_move_line + WHERE stock_move_line.picking_id = stock_picking.id) + """ + ) diff --git a/purchase_order_shipping_method/models/stock_picking.py b/purchase_order_shipping_method/models/stock_picking.py index 3215243154..de730cc420 100644 --- a/purchase_order_shipping_method/models/stock_picking.py +++ b/purchase_order_shipping_method/models/stock_picking.py @@ -24,18 +24,21 @@ class StockPicking(models.Model): ) license_plate = fields.Char(string="Transport License Plate") total_done_qty = fields.Float( - string="Total Done Quantity", compute="_compute_total_done_qty" + string="Total Done Quantity", compute="_compute_total_done_qty", store=True ) transport_price = fields.Float( string="Transport Price", compute="_compute_transport_price" ) + @api.depends( + "move_line_ids_without_package", "move_line_ids_without_package.qty_done" + ) def _compute_total_done_qty(self): for picking in self: picking.total_done_qty = 0 - if picking.move_ids_without_package: + if picking.move_line_ids_without_package: picking.total_done_qty = sum( - picking.move_ids_without_package.mapped("quantity_done") + picking.move_line_ids_without_package.mapped("qty_done") ) def _compute_transport_price(self):