Prevent editing list and cost prices without proper context

issue10773
review338951002
This commit is contained in:
Cédric Krier
2021-10-08 19:16:44 +02:00
parent f687a2ae96
commit 76b6e04cd6
5 changed files with 33 additions and 9 deletions
+1
View File
@@ -1,3 +1,4 @@
* Prevent editing list and cost prices without a company
* Make list price not required on product
* Provide digits from unit of measure
* Allow only fixed cost price as method for service
+27 -2
View File
@@ -75,6 +75,9 @@ class Template(
"regardless of stock level.")
list_price = fields.MultiValue(fields.Numeric(
"List Price", digits=price_digits,
states={
'readonly': ~Eval('context', {}).get('company'),
},
help="The standard price the product is sold at."))
list_prices = fields.One2Many(
'product.list_price', 'template', "List Prices")
@@ -360,7 +363,10 @@ class Product(
'product.identifier', 'product', "Identifiers",
help="Other identifiers associated with the variant.")
cost_price = fields.MultiValue(fields.Numeric(
"Cost Price", required=True, digits=price_digits,
"Cost Price", digits=price_digits,
states={
'readonly': ~Eval('context', {}).get('company'),
},
help="The amount it costs to purchase or make the variant, "
"or carry out the service."))
cost_prices = fields.One2Many(
@@ -478,9 +484,18 @@ class Product(
return pool.get('product.cost_price')
return super(Product, cls).multivalue_model(field)
def set_multivalue(self, name, value, save=True, **pattern):
context = Transaction().context
if name in {'cost_price', 'list_price'} and not value:
if not pattern.get('company', context.get('company')):
return []
return super().set_multivalue(name, value, save=save, **pattern)
@classmethod
def default_cost_price(cls, **pattern):
return Decimal(0)
context = Transaction().context
if pattern.get('company', context.get('company')):
return Decimal(0)
@classmethod
def search_template(cls, name, clause):
@@ -622,6 +637,11 @@ class ProductListPrice(ModelSQL, CompanyValueMixin):
depends=['company'])
list_price = fields.Numeric("List Price", digits=price_digits)
@classmethod
def __setup__(cls):
super().__setup__()
cls.company.required = True
@classmethod
def __register__(cls, module_name):
exist = backend.TableHandler.table_exist(cls._table)
@@ -713,6 +733,11 @@ class ProductCostPrice(ModelSQL, CompanyValueMixin):
cost_price = fields.Numeric(
"Cost Price", required=True, digits=price_digits)
@classmethod
def __setup__(cls):
super().__setup__()
cls.company.required = True
@classmethod
def __register__(cls, module_name):
pool = Pool()
-1
View File
@@ -21,7 +21,6 @@ Create product::
>>> template.name = 'product'
>>> template.default_uom = unit
>>> template.type = 'service'
>>> template.list_price = Decimal('40')
>>> template.save()
>>> product, = template.products
+5
View File
@@ -7,11 +7,16 @@ Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.tests.tools import activate_modules
>>> from trytond.modules.company.tests.tools import create_company
Activate modules::
>>> config = activate_modules('product')
Create company::
>>> _ = create_company()
Create a template::
>>> ProductUom = Model.get('product.uom')
-6
View File
@@ -279,7 +279,6 @@ class ProductTestCase(CompanyTestMixin, ModuleTestCase):
pt1, pt2 = Template.create([{
'name': 'P1',
'type': 'goods',
'list_price': Decimal(20),
'default_uom': kilogram.id,
'products': [('create', [{
'code': '1',
@@ -287,7 +286,6 @@ class ProductTestCase(CompanyTestMixin, ModuleTestCase):
}, {
'name': 'P2',
'type': 'goods',
'list_price': Decimal(20),
'default_uom': millimeter.id,
'products': [('create', [{
'code': '2',
@@ -318,7 +316,6 @@ class ProductTestCase(CompanyTestMixin, ModuleTestCase):
'name': 'Some product-1',
'categories': [('add', [category1.id])],
'type': 'goods',
'list_price': Decimal('10'),
'default_uom': uom.id,
'products': [('create', [{}])],
}
@@ -326,7 +323,6 @@ class ProductTestCase(CompanyTestMixin, ModuleTestCase):
'name': 'Some product-2',
'categories': [('add', [category2.id])],
'type': 'goods',
'list_price': Decimal('10'),
'default_uom': uom.id,
'products': [('create', [{}])],
}
@@ -397,14 +393,12 @@ class ProductTestCase(CompanyTestMixin, ModuleTestCase):
values1 = {
'name': 'Product A',
'type': 'assets',
'list_price': Decimal('10'),
'default_uom': uom.id,
'products': [('create', [{'suffix_code': 'AA'}])],
}
values2 = {
'name': 'Product B',
'type': 'goods',
'list_price': Decimal('10'),
'default_uom': uom.id,
'products': [('create', [{'suffix_code': 'BB'}])],
}