From 310121c00b8369c768bf0c3f3fd4ce069a24c8ce Mon Sep 17 00:00:00 2001 From: Wilson Gomez Date: Tue, 27 Jun 2023 17:06:04 -0500 Subject: [PATCH] add field quantity_mix_required --- exceptions.py | 3 +++ message.xml | 3 +++ product.py | 12 +++++++++++- tests/test_sale_pos_commission.py | 27 --------------------------- view/product_form.xml | 2 ++ 5 files changed, 19 insertions(+), 28 deletions(-) delete mode 100644 tests/test_sale_pos_commission.py diff --git a/exceptions.py b/exceptions.py index 8546dfd..5ca4431 100644 --- a/exceptions.py +++ b/exceptions.py @@ -15,3 +15,6 @@ class ProductionValidationWarning(UserWarning): class DeleteSaleError(ValidationError): pass + +class ProductMixRequiredError(UserError): + pass diff --git a/message.xml b/message.xml index e7ca511..29b950b 100644 --- a/message.xml +++ b/message.xml @@ -15,5 +15,8 @@ this repository contains the full copyright notices and license terms. --> The sale '%(sale)s' can not delete + + The quantity '%(quantity)s' must be less than '%(product_mix)s' in products mix + diff --git a/product.py b/product.py index 0c16396..a990567 100644 --- a/product.py +++ b/product.py @@ -2,14 +2,24 @@ # 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' diff --git a/tests/test_sale_pos_commission.py b/tests/test_sale_pos_commission.py deleted file mode 100644 index d0d3ab7..0000000 --- a/tests/test_sale_pos_commission.py +++ /dev/null @@ -1,27 +0,0 @@ -# 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 __future__ import unicode_literals - -import unittest -import doctest - -from trytond.tests.test_tryton import ModuleTestCase -from trytond.tests.test_tryton import suite as test_suite -from trytond.tests.test_tryton import doctest_setup, doctest_teardown -from trytond.tests.test_tryton import doctest_checker - - -class CommissionWaitingTestCase(ModuleTestCase): - 'Test Commission Waiting module' - module = 'commission_global' - - -def suite(): - suite = test_suite() - suite.addTests(unittest.TestLoader().loadTestsFromTestCase( - CommissionWaitingTestCase)) - suite.addTests(doctest.DocFileSuite('scenario_commission_global.rst', - setUp=doctest_setup, tearDown=doctest_teardown, encoding='utf-8', - checker=doctest_checker, - optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) - return suite diff --git a/view/product_form.xml b/view/product_form.xml index 9320a4a..0ae3a47 100644 --- a/view/product_form.xml +++ b/view/product_form.xml @@ -5,5 +5,7 @@ this repository contains the full copyright notices and license terms. --> +