1
votes

i want to add onchange function in module manufacturing (mrp.production) in view.xml

<record model="ir.ui.view" id="partner_instructur_form_view">
        <field name="name">mrp.production.form.instructur</field>
        <field name="model">mrp.production</field>
        <field name="inherit_id" ref="mrp.mrp_production_form_view" />
        <field name="arch" type="xml">
            <xpath expr="//field[@name='location_dest_id']" position="after">
                <field name="product_qty" on_change="onchange_hitung_kuota(product_qty, prod_qtys)"/>         
                <field name="prod_qtys" on_change="onchange_hitung_kuota(product_qty, prod_qtys)"/>
                <field name="progres_persen" widget="progressbar"/>      

            </xpath> 
        </field>
</record>

in python

class ala_mrp_prod(osv.osv):
    _inherit = 'mrp.production'

    def onchange_hitung_kuota(self, cr, uid, ids, prod_qtys, product_qty):
        kurangi = product_qty - prod_qtys
        res = {
            'value':{ 'progres_persen':  (kurangi * 100) / product_qty}
        }
        return res

    _columns = {  
        'prod_qtys':fields.integer('Jumlah Total'),
        'progres_persen': fields.float('Progres'),
    }

    _defaults = {
        'prod_qtys': 1,
    }
ala_mrp_prod()

enter image description here

  1. why product quantity show 2?
  2. so if i input product_quantity 3 , jumlah total 5 progres 40%? please help
3

3 Answers

1
votes

You passed parameters in the wrong order.
product_qty should be the first in onchange_hitung_kuota() method:

def onchange_hitung_kuota(self, cr, uid, ids, product_qty, prod_qtys)
1
votes

In odoo new api you do not need to modify the xml file. what you have to do is

class mrp_order(models.Model)
_inherit = 'mrp.production'

@api.onchange('product_qty', 'prod_qtys')
def onchange_hitung_kuota(self):
   kurangi = product_qty - prod_qtys
   self.progres_persen = (kurangi * 100) / self.product_qty

hope this helps!

0
votes

I think you inverted the two parameters inside the onchange_hitung_kuota function