Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions sale_order_secondary_unit/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,13 @@ class SaleOrderLine(models.Model):

product_uom_qty = fields.Float(copy=True)

@api.depends(
"display_type",
"product_id",
"product_packaging_qty",
@api.onchange(
"secondary_uom_qty",
"secondary_uom_id",
"product_uom_qty",
)
def _compute_product_uom_qty(self):
res = super()._compute_product_uom_qty()
def _compute_target_field_qty(self):
for line in self:
line._compute_helper_target_field_qty()
return res

@api.depends("product_id")
def _compute_product_uom(self):
Expand All @@ -42,12 +36,22 @@ def _compute_product_uom(self):

@api.onchange("product_id")
def _onchange_product_id_warning(self):
"""
If default sales secondary unit set on product, put on secondary
quantity 1 for being the default quantity. We override this method,
that is the one that sets by default 1 on the other quantity with that
purpose.
"""
res = super()._onchange_product_id_warning()
if self.product_id and not self.env.context.get("skip_secondary_uom_default"):
line_uom_qty = self.product_uom_qty
self.secondary_uom_id = self.product_id.sale_secondary_uom_id
if self.product_uom_qty == 1.0:
self.secondary_uom_qty = 1.0
self._onchange_helper_product_uom_for_secondary()
if self.secondary_uom_id:
if line_uom_qty == 1.0:
self.secondary_uom_qty = 1.0
self._compute_helper_target_field_qty()
else:
self.product_uom_qty = line_uom_qty
return res

@api.depends("secondary_uom_qty", "product_uom_qty", "price_unit")
Expand Down
Loading