summaryrefslogtreecommitdiff
path: root/addons/mrp_landed_costs/models/stock_landed_cost.py
blob: 5d991f8c7882516bf19bcd8674e26a371b10e95e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models, api


class StockLandedCost(models.Model):
    _inherit = 'stock.landed.cost'

    target_model = fields.Selection(selection_add=[
        ('manufacturing', "Manufacturing Orders")
    ], ondelete={'manufacturing': 'set default'})
    mrp_production_ids = fields.Many2many(
        'mrp.production', string='Manufacturing order',
        copy=False, states={'done': [('readonly', True)]}, groups='mrp.group_mrp_user')
    allowed_mrp_production_ids = fields.Many2many(
        'mrp.production', compute='_compute_allowed_mrp_production_ids', groups='mrp.group_mrp_user')

    @api.depends('company_id')
    def _compute_allowed_mrp_production_ids(self):
        for cost in self:
            moves = self.env['stock.move'].search([
                ('stock_valuation_layer_ids', '!=', False),
                ('production_id', '!=', False),
                ('company_id', '=', cost.company_id.id)
            ])
            self.allowed_mrp_production_ids = moves.production_id

    @api.onchange('target_model')
    def _onchange_target_model(self):
        super()._onchange_target_model()
        if self.target_model != 'manufacturing':
            self.mrp_production_ids = False

    def _get_targeted_move_ids(self):
        return super()._get_targeted_move_ids() | self.mrp_production_ids.move_finished_ids