Odoo Help

1

1
1 Answer
0
Andrew Brownrigg
30/01/18, 19:57

My Solution

I don't normally answer my own questions, but as I kept working through the problem, the solution formed.  Here we go.

_create_equipment method

Within the inherited purchase.order.line model, I defined the _create_equipment method.

@api.multi
def _create_equipment(self, picking):
equip = self.env['maintenance.equipment']
    done = self.env['maintenance.equipment'].browse()
    for line in self:
        if line.product_id.type != 'equip':
            continue
        price_unit = line._get_stock_move_price_unit()
        qty = 0.0
        for move in line.move_ids.filtered(lambda x: x.state != 'cancel'):
            qty += move.product_qty
        template = {
            # set field values
        }
        done += equip.create(template)
    return done

Ok. That's all fine and well, but from where to call the method? I ended up calling it from the do_transfer method of the stock.picking class.

@api.multi
def do_transfer(self):
    # unchanged code
    for picking in other_pickings:
        # more unchanged code
        for move in picking.move_lines
            rounding = move.product_id.uom_id.rounding
            remaining_qty = move.remaining_qty
            move.purchase_line_id._create_equipment(picking)
            # Remaining code unchanged   

Just like in the _create_picking method of the purchase.order model, I added equipment to the conditions in the _create_stock_moves method of the purchase.order.line model.

@api.multi
def _create_stock_moves(self, picking):
    # Unchanged Code
    for line in self:
        if line.product_id.type not in ['product', 'consu', 'equip']:
            continue
    # Remaining Code unchanged

Now, when a product is marked as Equipment, it will create an incoming shipment for the PO.  When receiving products, products of type Equipment will create records in the maintenance.equipment model.

Nest Steps

My next steps in the project will include some wizards, so that when receiving Equipment products, a wizard for each will be triggered, so the user can provide the additional information not included in the product.product and product.template models.

Ask a Question
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 E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now