Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty

I have a machine that needs to be calibrated before use, so the main raw material needs an extra quantity added to it (one extra unit) no matter how much is being consumed. 

This is because the first "run" of the machine checks that the raw material is flowing in and that the finished product is flowing out properly.  Once this is done, the production starts on the remaining raw material quantity.

No matter how much raw material I need, I always have to add a fixed amount of one unit, on top of what is calculated that is needed.

I would also like to round the quantity of the raw material up to the nearest 5 units (if not already a multiple of 5) so I can make full packages of finished product.


Example:

If the Manufacturing Order shows to consume 1,2,3 or 4 units then I would want an extra unit added and for each of these to show to consume 5 units.

If the Manufacturing Order shows to consume 5,6,7,8 or 9 units then I would want an extra unit added and for each of these to show to consume 10 units.

Avatar
Hylkää
Paras vastaus

Using Odoo Studio, add some fields to the Product so you can flag which components you want to adjust the quantities for:

Here we can add the following three fields (the first is a Boolean, the next two are Float fields):


These have the following names in this example:

<group name="studio_group_biHP0" string="BoM Adjustments">
  <field name="x_studio_adjust_quantity_on_bom" string="Adjust Qty on BoM"/>
  <field name="x_studio_bom_extra_qty" string="Extra Quantity"/>
  <field name="x_studio_round_to_nearest" string="Round to Nearest"/>
</group>


Then you can create a Server Action like this (tested with v14, if you use v13 you would use Warning instead of UserError in the Extra Credit section):


for record in records:
  for component in record.move_raw_ids:
    if component.product_id.x_studio_adjust_quantity_on_bom:
      new_qty = component.product_uom_qty + component.product_id.x_studio_bom_extra_qty
      component['product_uom_qty'] = new_qty + 1 - (new_qty + 1) % -component.product_id.x_studio_round_to_nearest


Be sure to click so that your Server Action shows up in the Action Menu on each single Manufacturing Order (and on the list of Manufacturing Orders).



You then get the following:
Extra Qty = 1; Round = 5 - an initial MO component quantity of 1,2,3 or 4 becomes 5
Extra Qty = 1; Round = 5 - an initial MO component quantity of 5,6,7,8 or 9 becomes 10
Extra Qty = 1; Round = 5 - an initial MO component quantity of 10,11,12,13,14 becomes 15


For reference:

https://realpython.com/python-modulo-operator/



Extra Credit:

You can create a field on the MO itself (a Boolean) to indicate if the BoM has already been bumped and check for this in the Server Action, so that if the MO has already been adjusted, the User sees a notification and quantities are not adjusted further.

First within the for record in records: loop (so on line 17, after checking and adjusting each component, at the same indent as the for on line 13):

record['x_bumped'] = True

Then prior to the for component in record.move_raw_ids: loop (so a new line 13 with all lines pushed down, at the same indent as the original line 13):

if record.x_bumped:
raise UserError("This Manufacturing Order has already been bumped!")



Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
syysk. 23
4177
2
elok. 25
786
2
elok. 24
4344
1
maalisk. 24
2060
2
kesäk. 21
3297