This question has been flagged
4 Replies
2138 Views

Here is my code 

 @api.multi

def button_plan(self):

quantity = []

res = super(MrpProduction, self).button_plan()

for production in self:

planned_date = fields.Datetime.from_string(self.date_planned_start)

production_values = {'date_planned_start_wo': False,

'date_planned_finished_wo': False,

'quantity': 0}

values = {}

print quantity

for workorder in production.workorder_ids:

date_start = planned_date

date_end = date_start + timedelta(minutes=workorder.duration_expected)

values['date_planned_start'] = fields.Datetime.to_string(date_start)

values['date_planned_finished'] = fields.Datetime.to_string(date_end)

values['quantity'] = fields.Float(quantity)

for operation in self.routing_id.operation_ids:

if operation.compute_equals_order_qty == True:

quantity = self.product_qty

print 'quantity', quantity

if operation.compute_equals_always_one == True:

quantity = 1.0

print 'quantity', quantity

if operation.compute_equals_workcenter == True:

quantity = operation.workcenter_quantity

print 'quantity', quantity

workorder.qty_workorder = quantity

print 'workorder.qty_workorder ::::',workorder.qty_workorder

workorder.write(values)

production_values['date_planned_finished_wo'] = fields.Datetime.to_string(planned_date)

production.write(production_values)

# production.write(values)

return res


The terminal output is 


quantity 1.0

quantity 35.0

quantity 56.0

workorder.qty_workorder :::: 56.0

2018-01-11 09:37:55,163 15380 WARNING odoo10 odoo.models: mrp.workorder.write() with unknown fields: quantity

quantity 1.0

quantity 35.0

quantity 56.0

workorder.qty_workorder :::: 56.0

2018-01-11 09:37:55,174 15380 WARNING odoo10 odoo.models: mrp.workorder.write() with unknown fields: quantity

quantity 1.0

quantity 35.0

quantity 56.0

workorder.qty_workorder :::: 56.0


Right output is: 

workorder.qty_workorder is 1, 35, 56 

Avatar
Discard

Your code is not properly structured, it is difficult to understand.

Author

Sorry, now understanding ?

Best Answer

Hello,

Try this:

@api.multi

def button_plan(self):

quantity = 0

res = super(MrpProduction, self).button_plan()

for production in self:

    for workorder in production.workorder_ids:     

         for operation in self.routing_id.operation_ids:

            if operation.compute_equals_order_qty == True:

                quantity = self.product_qty

            if operation.compute_equals_always_one == True:

                    quantity = 1.0

            if operation.compute_equals_workcenter == True:

                    quantity = operation.workcenter_quantity   

            workorder.qty_workorder = quantity

     return res


In your case , you applied 'workorder.qty_workorder = quantity' outside loop.
Make that happen inside loop.

Thanks,

Mayank Gosai

Avatar
Discard
Author

I fix this error,

workorder.write({'qty_workorder': quantity}) Thanks

Author Best Answer

 @api.multi

def button_plan(self):

quantity = 0

res = super(MrpProduction, self).button_plan()

for production in self:

    for workorder in production.workorder_ids:     

         for operation in self.routing_id.operation_ids:

            if operation.compute_equals_order_qty == True:

                quantity = self.product_qty

            if operation.compute_equals_always_one == True:

                    quantity = 1.0

            if operation.compute_equals_workcenter == True:

                    quantity = operation.workcenter_quantity   

         workorder.qty_workorder = quantity

     return res

------------------------------------------------------Output ---------------------------------------

quantity 1.0

quantity 35.0

quantity 56.0

workorder.qty_workorder :::: 56.0

quantity 1.0

quantity 35.0

quantity 56.0

workorder.qty_workorder :::: 56.0

quantity 1.0

quantity 35.0

quantity 56.0

workorder.qty_workorder :::: 56.0

---------------------------------------Righ Output --------------------------------

workorder.qty_workorder =1

workorder.qty_workorder=35

workorder.qty_workorder=56 

Sorry, now understand?




Avatar
Discard