31 lines
1.4 KiB
Python
31 lines
1.4 KiB
Python
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
from trytond.model import fields, ModelSQL
|
|
from trytond.pool import PoolMeta
|
|
from .exceptions import ProductMixRequiredError
|
|
from trytond.i18n import gettext
|
|
|
|
class Product(metaclass=PoolMeta):
|
|
__name__ = 'product.product'
|
|
products_mix = fields.Many2Many('product.product-mix.option',
|
|
'product', 'option', 'Mix')
|
|
tasks = fields.One2Many('production.configuration_task', 'product', 'Tasks')
|
|
quantity_mix_required = fields.Integer('Quantity Mix Required')
|
|
|
|
@fields.depends('products_mix', 'quantity_mix_required')
|
|
def on_change_quantity_mix_required(self, name=None):
|
|
if self.products_mix and self.quantity_mix_required and len(self.products_mix) < self.quantity_mix_required:
|
|
raise ProductMixRequiredError(
|
|
gettext(
|
|
"sale_pos_frontend_rest.msg_quantity_mix_error",
|
|
product_mix=len(self.products_mix),
|
|
quantity=self.quantity_mix_required))
|
|
|
|
class ProductMixOption(ModelSQL):
|
|
'Product Mix Option'
|
|
__name__ = 'product.product-mix.option'
|
|
product = fields.Many2One('product.product', 'Product',
|
|
ondelete='CASCADE', required=True, select=True)
|
|
option = fields.Many2One('product.product', 'Product',
|
|
ondelete='CASCADE', required=True, select=True)
|