Skip to content

Commit

Permalink
[FIX]stock_secondary_unit: partial delivery
Browse files Browse the repository at this point in the history
  • Loading branch information
jcadhoc authored and maq-adhoc committed Jan 6, 2025
1 parent 498e678 commit 9b03e8b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions stock_secondary_unit/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from . import product_product
from . import product_template
from . import stock_move
from . import stock_picking
8 changes: 8 additions & 0 deletions stock_secondary_unit/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.tools.float_utils import float_round


class StockMove(models.Model):
Expand Down Expand Up @@ -60,4 +61,11 @@ def create(self, vals_list):

@api.depends("secondary_uom_id", "secondary_uom_qty")
def _compute_qty_done(self):
import pdb; pdb.set_trace()
self._compute_helper_target_field_qty()

def _compute_helper_target_field_qty(self):
import pdb; pdb.set_trace()
if self.env.context.get('bypass_compute_field_qty', False):
return
super()._compute_helper_target_field_qty()
18 changes: 18 additions & 0 deletions stock_secondary_unit/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from odoo import models

class StockPicking(models.Model):
_inherit = "stock.picking"

def _create_backorder(self):
res = super(StockPicking, self)._create_backorder()
for original_move in self.move_ids:
corresponding_move = next((move for move in res.move_ids if move.product_id == original_move.product_id), None)
if corresponding_move and corresponding_move.secondary_uom_qty:
# To avoid rounding errors, Saving the current value of product_uom_qty
# before recalculating the secondary unit. Afterward, I'll restore the original value
product_uom_qty = corresponding_move.product_uom_qty
corresponding_move.with_context(bypass_compute_field_qty=True)._compute_secondary_uom_qty()
corresponding_move.product_uom_qty = product_uom_qty
else:
continue
return res

0 comments on commit 9b03e8b

Please sign in to comment.