This question has been flagged
2 Replies
5307 Views

I'm developing a solution for a small company which is dedicated to produce aromatic plats for cooking. The producction process is as follows: We plant a fixed cantity of a plant, the plant is feeded for a time, after is recolected and dryed an finally is packed on 5g package. The problem is that for a fixed quantity of plants we will never get the same wheight of dryed product. I think that it's a common issue because this variable produccion is related with all produccion process for natural products, as milk, honey, vegetables, meat, etc...

Is there any way to affort that problem?


Avatar
Discard
Author Best Answer

I get a possible solution making qty_done field as editable with a custom module. It seems to work properly, updating stock quantity without changing consumed materials. But still having an issue, i get two stock move lines, the orignal one with planned quantity of finished goods and other with increased quantity. Is there any way to avoid this constraints?, it makes really poor user friendly reports to final user.


[SOLVED]

After a little research i found a solution that works, i have'nt tested in production stage but i could'nt find errors on tests. If you use the solution and find some issues, please, post it here.

I made a custom module that overrides write and _compute_consumed_less_than_planed  to be able to save products produced independent of raw materials.

1. Set qty_done editable

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="mrp_production" model="ir.ui.view">
<field name="name">mrp.production.form</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view"/>
<field name="view_type">form</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='finished_move_line_ids']" position="attributes">
<attribute name="attrs">{'readonly': False}</attribute>
</xpath>
</field>
</record>
</odoo>

2. Override mrp_production methods

class mrp_production(models.Model):

_inherit = 'mrp.production'
        
    # Override write method to set equal quantity of product
    # on stock_move and stock_move_line relation
@api.multi
def write (self, vals):
if "finished_move_line_ids" in vals.keys():

id_move = self["move_finished_ids"]["id"]
qty = vals["finished_move_line_ids"][0][2]["qty_done"]
dominio = [('id', '=', id_move)]

move = self.env["stock.move"].search(dominio)
move.write({'ordered_qty': qty, 'product_uom_qty': qty})

res = super(mrp_production, self).write(vals)

return res


    #Avoid warning on consumed less than planned after increase product quantity
@api.multi
@api.depends
('move_raw_ids.quantity_done', 'move_raw_ids.product_uom_qty')
def _compute_consumed_less_than_planned(self):

for order in self:
order.consumed_less_than_planned = False
Avatar
Discard
Best Answer

Try this alternative solution.


Create an indicator for lists of materials with variable production

You must put the components of the BOM by default 1.

Make the production fill the consumption and result.
By marking as a fact, the respective consumption and planned result is assigned
class MrpBom(models.Model):
_inherit = 'mrp.bom'
variable_result = fields.Boolean('Resultado Variable'
, default=False,
help="Si es verdadero, la cantidad de productos resultantes son variables y no dependen del consumo.")


class MrpProduction(models.Model):
_inherit = 'mrp.production'


@api.multi
def button_mark_done(self):
if self.bom_id.variable_result:
for move_raw in self.move_raw_ids:
qty = move_raw.quantity_done
move_raw.write({'product_uom_qty': qty}) #'ordered_qty': qty,

for move_line in self.finished_move_line_ids:
qty = move_line.qty_done
dominio = [('id', '=', move_line.move_id.id)]
move = self.env["stock.move"].search(dominio)
move.update({'ordered_qty': qty, 'product_uom_qty': qty})

# move_line.write({'product_uom_qty': qty}) #'ordered_qty': qty,

return super(MrpProduction, self).button_mark_done()


Avatar
Discard