flectra/addons/purchase_mrp/models/purchase_mrp.py
2018-01-16 02:34:37 -08:00

42 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
from flectra import fields, models
from flectra.tools import float_compare
class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line'
qty_received = fields.Float(compute='_compute_qty_received', string="Received Qty", store=True)
def _compute_qty_received(self):
super(PurchaseOrderLine, self)._compute_qty_received()
for line in self.filtered(lambda x: x.move_ids and x.product_id.id not in x.move_ids.mapped('product_id').ids):
bom = self.env['mrp.bom']._bom_find(product=line.product_id, company_id=line.company_id.id)
if bom and bom.type == 'phantom':
line.qty_received = line._get_bom_delivered(bom=bom)
def _get_bom_delivered(self, bom=False):
self.ensure_one()
# In the case of a kit, we need to check if all components are shipped. Since the BOM might
# have changed, we don't compute the quantities but verify the move state.
if bom:
bom_delivered = all([move.state == 'done' for move in self.move_ids])
if bom_delivered:
return self.product_qty
else:
return 0.0
class StockMove(models.Model):
_inherit = 'stock.move'
def _prepare_phantom_move_values(self, bom_line, quantity):
vals = super(StockMove, self)._prepare_phantom_move_values(bom_line, quantity)
if self.purchase_line_id:
vals['purchase_line_id'] = self.purchase_line_id.id
return vals