diff options
| author | jem-odoo <jem@openerp.com> | 2018-06-04 09:50:12 +0000 |
|---|---|---|
| committer | jem-odoo <jem@openerp.com> | 2018-10-30 12:43:53 +0000 |
| commit | 3e3d6c3ce0577d0611c17d27b7a459fd7ec886e9 (patch) | |
| tree | 518c3c962ad4b5d75afb73cbfe783306904d5b79 /addons/purchase_mrp | |
| parent | 7c1ae0cf491b8a95d8777e3c357e614bc8c69123 (diff) | |
[REF] purchase_*: change received qty api
The received quantity on Purchase Order line can be compared
to the delivered qty on Sales Order line. It is now time for
both to share the same mecanism (introduced in
3bf8a62e0dd99f7dad42718f895abf4fd53f996f).
This commit sets `qty_received` as a computed field, depending
of a method (`qty_received_method` field) to compute it. The
value can be computed based on
- manual value; for services (all the time), and consummable
products (when stock is not installed).
- stock moves; for stockable and consummable products (when
stock is installed)
This is now easier to extend the way the received quantity
need to be computed (like in sale).
Task #1850689
closes odoo/odoo#27663
Diffstat (limited to 'addons/purchase_mrp')
| -rw-r--r-- | addons/purchase_mrp/models/purchase_mrp.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/addons/purchase_mrp/models/purchase_mrp.py b/addons/purchase_mrp/models/purchase_mrp.py index c554d64e152..176c86cb358 100644 --- a/addons/purchase_mrp/models/purchase_mrp.py +++ b/addons/purchase_mrp/models/purchase_mrp.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import api, fields, models from odoo.tools import float_compare @@ -14,12 +14,14 @@ class MrpProduction(models.Model): class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' - def _update_received_qty(self): - super(PurchaseOrderLine, self)._update_received_qty() - 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) + @api.multi + def _compute_qty_received(self): + super(PurchaseOrderLine, self)._compute_qty_received() + for line in self: + if line.qty_received_method == 'stock_moves' and line.move_ids and line.product_id.id not in line.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() |
