In order to improve the navigation between of SO and PO in the case of MTO, add a direct link between PO<->SO. When the SO is confirmed (with storable product(s) with MTO + buy), PO is/are generated, in this case, add a stat button on each model form to avoid to manually search the related SO with the source field (name). task-1913392
27 lines
1.3 KiB
Python
27 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class PurchaseOrderLine(models.Model):
|
|
_inherit = 'purchase.order.line'
|
|
|
|
def _prepare_stock_moves(self, picking):
|
|
res = super(PurchaseOrderLine, self)._prepare_stock_moves(picking)
|
|
for re in res:
|
|
re['sale_line_id'] = self.sale_line_id.id
|
|
return res
|
|
|
|
def _find_candidate(self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values):
|
|
# if this is defined, this is a dropshipping line, so no
|
|
# this is to correctly map delivered quantities to the so lines
|
|
lines = self.filtered(lambda po_line: po_line.sale_line_id.id == values['sale_line_id']) if values.get('sale_line_id') else self
|
|
return super(PurchaseOrderLine, lines)._find_candidate(product_id, product_qty, product_uom, location_id, name, origin, company_id, values)
|
|
|
|
@api.model
|
|
def _prepare_purchase_order_line_from_procurement(self, product_id, product_qty, product_uom, company_id, values, po):
|
|
res = super()._prepare_purchase_order_line_from_procurement(product_id, product_qty, product_uom, company_id, values, po)
|
|
res['sale_line_id'] = values.get('sale_line_id', False)
|
|
return res
|