Skip to content

[6807][ADD] sale_order_secondary_unit_convert#256

Open
smorita7749 wants to merge 2 commits into
18.0from
6807-add-sale_order_secondary_unit_convert
Open

[6807][ADD] sale_order_secondary_unit_convert#256
smorita7749 wants to merge 2 commits into
18.0from
6807-add-sale_order_secondary_unit_convert

Conversation

@smorita7749

Copy link
Copy Markdown
Contributor

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".

@smorita7749

Copy link
Copy Markdown
Contributor Author

I will add translation when I find the approach is appropriate through reviewing.

@AungKoKoLin1997

Copy link
Copy Markdown
Contributor

@smorita7749 Please update the PR title. Seem like wrong.

@smorita7749 smorita7749 changed the title [6807][ADD] sale_order_secondary_unit [6807][ADD] sale_order_secondary_unit_convert Jun 12, 2026
@smorita7749 smorita7749 force-pushed the 6807-add-sale_order_secondary_unit_convert branch from 4d89059 to 9302ca8 Compare June 12, 2026 08:43

@AungKoKoLin1997 AungKoKoLin1997 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

@smorita7749

Copy link
Copy Markdown
Contributor Author

@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.
They receive POs in bundles, but they want to show the POs lines and invoices to their customers in bags, which means a conversion between secondary units is needed.

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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a strange field name and label for me. As far as I understand the business requirement, may be like "Customer Secondary UoM"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "Customer Secondary UoM" is better since this field is not shown to customers. How about "Internal Secondary Unit"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is acceptable.

string="Input Unit",
)
input_secondary_qty = fields.Float(
string="Input Qty",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Comment on lines +46 to +55
@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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of that, isn't better to have inverse method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +37 to +44
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants