feat: Refactor packaging fields to use product.uom for quantity calculations and remove group restrictions.

This commit is contained in:
Suherdy Yacob 2026-01-20 16:53:29 +07:00
parent 49db20c6d4
commit c305b0f113
3 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{ {
'name': 'MRP Packaging Quantity', 'name': 'MRP Packaging Quantity',
'version': '18.0.1.0.0', 'version': '19.0.1.0.1',
'category': 'Manufacturing', 'category': 'Manufacturing',
'summary': 'Add packaging fields to Manufacturing Orders', 'summary': 'Add packaging fields to Manufacturing Orders',
'description': """ 'description': """
@ -8,7 +8,7 @@
It allows users to define the quantity to produce based on the selected packaging and its quantity. It allows users to define the quantity to produce based on the selected packaging and its quantity.
""", """,
'author': 'Suherdy Yacob', 'author': 'Suherdy Yacob',
'depends': ['mrp'], 'depends': ['mrp', 'product'],
'data': [ 'data': [
'views/mrp_production_views.xml', 'views/mrp_production_views.xml',
], ],

View File

@ -3,10 +3,10 @@ from odoo import api, fields, models
class MrpProduction(models.Model): class MrpProduction(models.Model):
_inherit = 'mrp.production' _inherit = 'mrp.production'
packaging_id = fields.Many2one('product.packaging', string='Packaging', domain="[('product_id', '=', product_id)]", check_company=True) packaging_id = fields.Many2one('product.uom', string='Packaging', domain="[('product_id', '=', product_id)]", check_company=True)
packaging_qty = fields.Float('Quantity Packaging', default=0.0, digits='Product Unit of Measure') packaging_qty = fields.Float('Quantity Packaging', default=0.0, digits='Product Unit of Measure')
@api.onchange('packaging_id', 'packaging_qty') @api.onchange('packaging_id', 'packaging_qty')
def _onchange_packaging_qty(self): def _onchange_packaging_qty(self):
if self.packaging_id and self.packaging_qty: if self.packaging_id and self.packaging_qty:
self.product_qty = self.packaging_id.qty * self.packaging_qty self.product_qty = self.packaging_id.uom_id._compute_quantity(self.packaging_qty, self.product_uom_id)

View File

@ -6,8 +6,8 @@
<field name="inherit_id" ref="mrp.mrp_production_form_view"/> <field name="inherit_id" ref="mrp.mrp_production_form_view"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='product_qty']/.." position="after"> <xpath expr="//field[@name='product_qty']/.." position="after">
<field name="packaging_id" groups="product.group_stock_packaging"/> <field name="packaging_id"/>
<field name="packaging_qty" groups="product.group_stock_packaging"/> <field name="packaging_qty"/>
</xpath> </xpath>
</field> </field>
</record> </record>