Odoo Help

0

0
2 Answers
0
Waldemar Tapia
2‏/6‏/2019 9:33 م

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()


0
eLengua
1‏/1‏/2019 7:42 م

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
Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now