Files
odoo_source/addons/purchase_mrp/models/mrp_production.py
T
Arnold Moyaux 05ae07c1a7 [FIX] (purchase_)mrp: Correct links with MO and PO
Fine tuning of commit 6acfb2e
It correctly merge the purchase.order in case of direct link and
avoid to relaunch the procurement.

It also correctly set the created_production_id if the demand come
from a SO

closes odoo/odoo#85301

X-original-commit: 9b6fa6c3db55daa3533c0d5cb13da7c98fc3e936
Signed-off-by: Arnold Moyaux <arm@odoo.com>
2022-02-25 09:22:52 +00:00

53 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
class MrpProduction(models.Model):
_inherit = 'mrp.production'
purchase_order_count = fields.Integer(
"Count of generated PO",
compute='_compute_purchase_order_count',
groups='purchase.group_purchase_user')
@api.depends('procurement_group_id.stock_move_ids.created_purchase_line_id.order_id', 'procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id')
def _compute_purchase_order_count(self):
for production in self:
production.purchase_order_count = len(production.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id |
production.procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id)
def action_view_purchase_orders(self):
self.ensure_one()
purchase_order_ids = (self.procurement_group_id.stock_move_ids.created_purchase_line_id.order_id | self.procurement_group_id.stock_move_ids.move_orig_ids.purchase_line_id.order_id).ids
action = {
'res_model': 'purchase.order',
'type': 'ir.actions.act_window',
}
if len(purchase_order_ids) == 1:
action.update({
'view_mode': 'form',
'res_id': purchase_order_ids[0],
})
else:
action.update({
'name': _("Purchase Order generated from %s", self.name),
'domain': [('id', 'in', purchase_order_ids)],
'view_mode': 'tree,form',
})
return action
def _get_document_iterate_key(self, move_raw_id):
iterate_key = super(MrpProduction, self)._get_document_iterate_key(move_raw_id)
if not iterate_key and move_raw_id.created_purchase_line_id:
iterate_key = 'created_purchase_line_id'
return iterate_key
def _prepare_merge_orig_links(self):
origs = super()._prepare_merge_orig_links()
for move in self.move_raw_ids:
if move.created_purchase_line_id:
origs[move.bom_line_id.id]['created_purchase_line_id'] = move.created_purchase_line_id
return origs