Document rules and enforce price value uniqueness

This commit is contained in:
AzureAD\SylvainDUVERNAY
2026-05-07 15:02:15 +02:00
parent 8fb6d681a0
commit eaae2e5b40
11 changed files with 647 additions and 153 deletions

View File

@@ -3,6 +3,9 @@
this repository contains the full copyright notices and license terms. -->
<tryton>
<data grouped="1">
<record model="ir.message" id="msg_price_value_unique">
<field name="text">Only one price value is allowed for each price index and price date.</field>
</record>
<record model="ir.message" id="msg_party_code_unique">
<field name="text">The code on party must be unique.</field>
</record>

View File

@@ -9,7 +9,7 @@ from trytond.i18n import gettext
from trytond.model import (
DeactivableMixin, Index, ModelSQL, ModelView, MultiValueMixin, Unique,
ValueMixin, convert_from, fields, sequence_ordered)
from trytond.model.exceptions import AccessError
from trytond.model.exceptions import AccessError, ValidationError
from trytond.pool import Pool
from trytond.pyson import Bool, Eval
from trytond.tools import is_full_text, lstrip_wildcard
@@ -38,12 +38,34 @@ class PriceValue(
price_value = fields.Float("Price value")
open_price = fields.Float("Open price")
low_price = fields.Float("Low price")
high_price = fields.Float("High price")
def get_price_index(self, name):
if self.price:
return self.price.price_index
return None
high_price = fields.Float("High price")
@classmethod
def validate(cls, price_values):
super().validate(price_values)
cls.check_unique_price_date(price_values)
@classmethod
def check_unique_price_date(cls, price_values):
domains = []
for price_value in price_values:
if not price_value.price or not price_value.price_date:
continue
domain = [
('price', '=', price_value.price.id),
('price_date', '=', price_value.price_date),
]
if price_value.id:
domain.append(('id', '!=', price_value.id))
domains.append(['AND'] + domain)
if domains and cls.search(['OR'] + domains, limit=1):
raise ValidationError(
gettext('price.msg_price_value_unique'))
def get_price_index(self, name):
if self.price:
return self.price.price_index
return None
class PriceValueReport(
ModelSQL, ModelView):