[6807][ADD] sale_order_secondary_unit_convert#256
Conversation
|
I will add translation when I find the approach is appropriate through reviewing. |
|
@smorita7749 Please update the PR title. Seem like wrong. |
4d89059 to
9302ca8
Compare
AungKoKoLin1997
left a comment
There was a problem hiding this comment.
@smorita7749 I failed to understand the usage of this module. Why we need a new secondary uom field for sale order line since we already have sale_order_secondary_unit module. Am I missing something?
Some products are managed with a base unit, kg and some secondary units, bundle and bag. Originally, I thought the conversion should be on the wizard, but since it should be saved, I decided is should be on the lines. |
|
|
||
| input_secondary_uom_id = fields.Many2one( | ||
| comodel_name="product.secondary.unit", | ||
| string="Input Unit", |
There was a problem hiding this comment.
It is a strange field name and label for me. As far as I understand the business requirement, may be like "Customer Secondary UoM"
There was a problem hiding this comment.
I don't think "Customer Secondary UoM" is better since this field is not shown to customers. How about "Internal Secondary Unit"?
| string="Input Unit", | ||
| ) | ||
| input_secondary_qty = fields.Float( | ||
| string="Input Qty", |
| @api.onchange("input_secondary_qty") | ||
| def _onchange_input_secondary(self): | ||
| uom = self.input_secondary_uom_id | ||
| if not uom or uom.dependency_type == "independent" or not self.product_id: | ||
| return | ||
| base_qty = self.input_secondary_qty * (uom.factor or 1.0) | ||
| self.product_uom_qty = self.product_id.uom_id._compute_quantity( | ||
| base_qty, self.product_uom | ||
| ) | ||
| self.env.remove_to_compute(self._fields["input_secondary_qty"], self) |
There was a problem hiding this comment.
Instead of that, isn't better to have inverse method?
There was a problem hiding this comment.
That makes sense! Done.
My understanding for now is if the field is computed and not read-only, inverse method is better to keep consistency.
| def _secondary_base_qty(self): | ||
| self.ensure_one() | ||
| qty = self.product_uom_qty | ||
| uom_line = self.product_uom | ||
| uom_product = self.product_id.uom_id | ||
| if uom_line and uom_product and uom_line != uom_product: | ||
| qty = uom_line._compute_quantity(qty, uom_product) | ||
| return qty |
There was a problem hiding this comment.
Move this above compute method and will be better to include qty conversion in this method and rename the field to like "_convert_qty_to_customer_secondary_uom".
QT6807
This module lets users enter sale order line quantities in a convenient input secondary unit while the line keeps being displayed in another secondary unit.
For example, a product may be handled internally in "Bundle" but sold to the customer in "Bag". Users can enter the quantity in "Bundle", and it is automatically converted so that the line shows the quantity in "Bag".