bug th qt

This commit is contained in:
2026-04-09 20:23:09 +02:00
parent a1ab7dec82
commit 8b9787d4c0
3 changed files with 40 additions and 8 deletions

View File

@@ -139,10 +139,14 @@ class Component(metaclass=PoolMeta):
if self.line:
return self.line.unit
def get_quota_purchase(self, name):
if self.line:
if self.line.quantity:
return round(self.line.quantity_theorical / (self.nbdays if self.nbdays > 0 else 1),5)
def get_quota_purchase(self, name):
if self.line:
quantity = getattr(self.line, 'quantity_theorical', None)
if quantity is None:
quantity = getattr(self.line, 'quantity', None)
if quantity is not None:
nbdays = self.nbdays if self.nbdays and self.nbdays > 0 else 1
return round(Decimal(quantity) / nbdays, 5)
class Pricing(metaclass=PoolMeta):
"Pricing"

View File

@@ -103,10 +103,14 @@ class Component(metaclass=PoolMeta):
if self.sale_line:
return self.sale_line.unit
def get_quota_sale(self, name):
if self.sale_line:
if self.sale_line.quantity:
return round(self.sale_line.quantity_theorical / (self.nbdays if self.nbdays > 0 else 1),4)
def get_quota_sale(self, name):
if self.sale_line:
quantity = getattr(self.sale_line, 'quantity_theorical', None)
if quantity is None:
quantity = getattr(self.sale_line, 'quantity', None)
if quantity is not None:
nbdays = self.nbdays if self.nbdays and self.nbdays > 0 else 1
return round(Decimal(quantity) / nbdays, 4)
class Pricing(metaclass=PoolMeta):
"Pricing"

View File

@@ -184,6 +184,30 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(
PurchaseLine.default_pricing_rule(), 'Default pricing rule')
def test_component_quota_uses_quantity_fallback_when_theoretical_is_missing(self):
'component quota does not crash when theoretical quantity is still empty'
SaleComponent = Pool().get('pricing.component')
PurchaseComponent = Pool().get('pricing.component')
sale_component = SaleComponent()
sale_component.nbdays = None
sale_component.sale_line = Mock(
quantity=Decimal('12'),
quantity_theorical=None,
)
purchase_component = PurchaseComponent()
purchase_component.nbdays = None
purchase_component.line = Mock(
quantity=Decimal('15'),
quantity_theorical=None,
)
self.assertEqual(sale_component.get_quota_sale('quota_sale'), Decimal('12.0000'))
self.assertEqual(
purchase_component.get_quota_purchase('quota'),
Decimal('15.00000'))
def test_sale_and_purchase_trader_operator_domains_use_explicit_categories(self):
'sale and purchase trader/operator fields are filtered by TRADER/OPERATOR categories'
Sale = Pool().get('sale.sale')