Files
manufacture/mrp_repair_refurbish/models/product_template.py
2017-09-19 13:34:23 +02:00

46 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
# © 2016 Cyril Gaudin (Camptocamp)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
refurbish_product_id = fields.Many2one(
comodel_name='product.product', string='Refurbished Product',
compute='_compute_refurbish_product',
inverse='_set_refurbish_product', search='_search_refurbish_product',
domain="[('type', '=', 'product')]")
property_stock_refurbish = fields.Many2one(
comodel_name='stock.location', string="Refurbish Location",
company_dependent=True, domain=[('usage', 'like', 'production')],
help="This stock location will be used, instead of the "
"default one, as the source location for "
"stock moves generated by repair orders when refurbishing takes "
"place.")
@api.depends('product_variant_ids',
'product_variant_ids.refurbish_product_id')
def _compute_refurbish_product(self):
unique_variants = self.filtered(lambda template:
len(template.product_variant_ids) == 1)
for template in unique_variants:
template.refurbish_product_id = \
template.product_variant_ids.refurbish_product_id
for template in (self - unique_variants):
template.refurbish_product_id = False
@api.one
def _set_refurbish_product(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.refurbish_product_id = \
self.refurbish_product_id
def _search_refurbish_product(self, operator, value):
products = self.env['product.product'].search([
('refurbish_product_id', operator, value)], limit=None)
return [('id', 'in', products.mapped('product_tmpl_id').ids)]