Skip to content

Commit

Permalink
[14.0][IMP] purchase_order_shipping_method: Add store true to a conpu…
Browse files Browse the repository at this point in the history
…te fieldd
  • Loading branch information
Tu Nombre committed Oct 18, 2024
1 parent 6fc87f2 commit 757fd90
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
3 changes: 2 additions & 1 deletion purchase_order_shipping_method/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -25,4 +25,5 @@
"views/transport_carrier_lines_to_invoice_view.xml",
],
"installable": True,
"pre_init_hook": "pre_init_hook",
}
Original file line number Diff line number Diff line change
@@ -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)
"""
)
9 changes: 6 additions & 3 deletions purchase_order_shipping_method/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 757fd90

Please sign in to comment.