mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
mrp_subcontracting_purchase: new module copied from 15.0
Add a new module to add smart buttons between a subcontracting purchase order and the ressuply component delivery. task-2486811 Part-of: odoo/odoo#75041
This commit is contained in:
5
mrp_subcontracting_purchase/models/__init__.py
Normal file
5
mrp_subcontracting_purchase/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import stock_picking
|
||||
from . import purchase_order
|
||||
25
mrp_subcontracting_purchase/models/purchase_order.py
Normal file
25
mrp_subcontracting_purchase/models/purchase_order.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class PurchaseOrder(models.Model):
|
||||
_inherit = 'purchase.order'
|
||||
|
||||
subcontracting_resupply_picking_count = fields.Integer(
|
||||
"Count of Subcontracting Resupply", compute='_compute_subcontracting_resupply_picking_count',
|
||||
help="Count of Subcontracting Resupply for component")
|
||||
|
||||
@api.depends('order_line.move_ids')
|
||||
def _compute_subcontracting_resupply_picking_count(self):
|
||||
for purchase in self:
|
||||
purchase.subcontracting_resupply_picking_count = len(purchase._get_subcontracting_resupplies())
|
||||
|
||||
def action_view_subcontracting_resupply(self):
|
||||
return self._get_action_view_picking(self._get_subcontracting_resupplies())
|
||||
|
||||
def _get_subcontracting_resupplies(self):
|
||||
moves_subcontracted = self.order_line.move_ids.filtered(lambda m: m.is_subcontract)
|
||||
subcontracted_productions = moves_subcontracted.move_orig_ids.production_id
|
||||
return subcontracted_productions.picking_ids
|
||||
40
mrp_subcontracting_purchase/models/stock_picking.py
Normal file
40
mrp_subcontracting_purchase/models/stock_picking.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
subcontracting_source_purchase_count = fields.Integer(
|
||||
"Number of subcontracting PO Source", compute='_compute_subcontracting_source_purchase_count',
|
||||
help="Number of subcontracting Purchase Order Source")
|
||||
|
||||
@api.depends('move_lines.move_dest_ids.raw_material_production_id')
|
||||
def _compute_subcontracting_source_purchase_count(self):
|
||||
for picking in self:
|
||||
picking.subcontracting_source_purchase_count = len(picking._get_subcontracting_source_purchase())
|
||||
|
||||
def action_view_subcontracting_source_purchase(self):
|
||||
purchase_order_ids = self._get_subcontracting_source_purchase().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': _("Source PO of %s", self.name),
|
||||
'domain': [('id', 'in', purchase_order_ids)],
|
||||
'view_mode': 'tree,form',
|
||||
})
|
||||
return action
|
||||
|
||||
def _get_subcontracting_source_purchase(self):
|
||||
moves_subcontracted = self.move_lines.move_dest_ids.raw_material_production_id.move_finished_ids.move_dest_ids.filtered(lambda m: m.is_subcontract)
|
||||
return moves_subcontracted.purchase_line_id.order_id
|
||||
Reference in New Issue
Block a user