main #7
@@ -731,7 +731,7 @@ class AssayLine(ModelSQL, ModelView):
|
|||||||
|
|
||||||
element = fields.Many2One('assay.element', "Element")
|
element = fields.Many2One('assay.element', "Element")
|
||||||
|
|
||||||
value = fields.Float("Value")
|
value = fields.Numeric("Value")
|
||||||
|
|
||||||
unit = fields.Many2One('assay.unit', "Unit")
|
unit = fields.Many2One('assay.unit', "Unit")
|
||||||
|
|
||||||
@@ -813,15 +813,14 @@ class PenaltyRuleTier(ModelSQL, ModelView):
|
|||||||
deduction_per_unit = fields.Numeric("Deduction / unit")
|
deduction_per_unit = fields.Numeric("Deduction / unit")
|
||||||
penalty_value = fields.Numeric("Penalty Value (USD/DMT)")
|
penalty_value = fields.Numeric("Penalty Value (USD/DMT)")
|
||||||
|
|
||||||
def compute_tier_penalty(self, grade, dry_weight_dmt):
|
def compute_tier_penalty(self, grade):
|
||||||
"""
|
"""
|
||||||
Retourne la pénalité USD pour ce palier uniquement.
|
Retourne la pénalité USD pour ce palier uniquement.
|
||||||
grade : Decimal – teneur brute de l'élément
|
grade : Decimal – teneur brute de l'élément
|
||||||
dry_weight_dmt: Decimal – poids sec en DMT
|
dry_weight_dmt: Decimal – poids sec en DMT
|
||||||
"""
|
"""
|
||||||
grade = Decimal(str(grade))
|
grade = Decimal(str(grade))
|
||||||
dry_weight_dmt = Decimal(str(dry_weight_dmt))
|
|
||||||
|
|
||||||
# Grade en dessous du seuil bas → ce palier ne s'applique pas
|
# Grade en dessous du seuil bas → ce palier ne s'applique pas
|
||||||
if grade <= self.threshold_from:
|
if grade <= self.threshold_from:
|
||||||
return Decimal(0)
|
return Decimal(0)
|
||||||
@@ -831,7 +830,7 @@ class PenaltyRuleTier(ModelSQL, ModelView):
|
|||||||
excess = excess_top - self.threshold_from
|
excess = excess_top - self.threshold_from
|
||||||
|
|
||||||
# USD/DMT × DMT
|
# USD/DMT × DMT
|
||||||
return (excess * self.penalty_value * dry_weight_dmt).quantize(Decimal('0.01'))
|
return (excess * self.penalty_value).quantize(Decimal('0.01'))
|
||||||
|
|
||||||
|
|
||||||
class PenaltyRule(ModelSQL, ModelView):
|
class PenaltyRule(ModelSQL, ModelView):
|
||||||
@@ -841,18 +840,17 @@ class PenaltyRule(ModelSQL, ModelView):
|
|||||||
element = fields.Many2One('assay.element', "Element")
|
element = fields.Many2One('assay.element', "Element")
|
||||||
tiers = fields.One2Many('penalty.rule.tier', 'rule', "Tiers")
|
tiers = fields.One2Many('penalty.rule.tier', 'rule', "Tiers")
|
||||||
|
|
||||||
def compute_penalty(self, grade, dry_weight_dmt):
|
def compute_penalty(self, grade):
|
||||||
"""
|
"""
|
||||||
Retourne la pénalité totale USD en cumulant tous les paliers traversés.
|
Retourne la pénalité totale USD en cumulant tous les paliers traversés.
|
||||||
grade : Decimal – teneur brute de l'élément
|
grade : Decimal – teneur brute de l'élément
|
||||||
dry_weight_dmt: Decimal – poids sec en DMT
|
dry_weight_dmt: Decimal – poids sec en DMT
|
||||||
"""
|
"""
|
||||||
grade = Decimal(str(grade))
|
grade = Decimal(str(grade))
|
||||||
dry_weight_dmt = Decimal(str(dry_weight_dmt))
|
|
||||||
|
|
||||||
total = Decimal(0)
|
total = Decimal(0)
|
||||||
for tier in self.tiers:
|
for tier in self.tiers:
|
||||||
total += tier.compute_tier_penalty(grade, dry_weight_dmt)
|
total += tier.compute_tier_penalty(grade)
|
||||||
|
|
||||||
return total.quantize(Decimal('0.01'))
|
return total.quantize(Decimal('0.01'))
|
||||||
|
|
||||||
@@ -873,7 +871,7 @@ class ConcentrateTerm(ModelSQL, ModelView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
manual_price = fields.Numeric(
|
manual_price = fields.Numeric(
|
||||||
"Manual Price",
|
"Price",
|
||||||
digits=(16, 6)
|
digits=(16, 6)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1325,16 +1323,30 @@ class Line(metaclass=PoolMeta):
|
|||||||
TR = Pool().get('pricing.trigger')
|
TR = Pool().get('pricing.trigger')
|
||||||
TR.save([tr])
|
TR.save([tr])
|
||||||
|
|
||||||
|
def get_element_grade(self, state, element):
|
||||||
|
if self.assays:
|
||||||
|
for assay in self.assays:
|
||||||
|
if assay.type == state:
|
||||||
|
for line in assay.lines:
|
||||||
|
if line.element == element:
|
||||||
|
return line.value
|
||||||
|
|
||||||
def check_pricing(self):
|
def check_pricing(self):
|
||||||
if self.terms and self.update_pricing:
|
if self.terms and self.update_pricing:
|
||||||
Pricing = Pool().get('pricing.component')
|
Concentrate = Pool().get('concentrate.term')
|
||||||
pricings = Pricing.search(['line','=',self.id])
|
|
||||||
if pricings:
|
|
||||||
Pricing.delete(pricings)
|
|
||||||
for t in self.terms:
|
for t in self.terms:
|
||||||
pc = Pricing()
|
if not t.component:
|
||||||
pc.curve = t.curve
|
grade = self.get_element_grade(self.assay_state,t.element)
|
||||||
|
logger.info("GRADE:%s",grade)
|
||||||
|
if grade:
|
||||||
|
cp = [c for c in self.price_summary if c.price_component == t.component]
|
||||||
|
if cp:
|
||||||
|
cp = cp[0]
|
||||||
|
price = cp.get_last_price()
|
||||||
|
logger.info("PRICE:%s",price)
|
||||||
|
t.manual_price = t.payable_rule.compute_payable_quantity(grade) * price / Decimal(100) - t.penalty_rules.compute_penalty(grade,self.quantity)
|
||||||
|
Concentrate.save([t])
|
||||||
|
|
||||||
if self.price_components:
|
if self.price_components:
|
||||||
for pc in self.price_components:
|
for pc in self.price_components:
|
||||||
if not pc.auto:
|
if not pc.auto:
|
||||||
|
|||||||
@@ -3,4 +3,7 @@
|
|||||||
<field name="component"/>
|
<field name="component"/>
|
||||||
<field name="payable_rule"/>
|
<field name="payable_rule"/>
|
||||||
<field name="penalty_rules"/>
|
<field name="penalty_rules"/>
|
||||||
|
<field name="manual_price"/>
|
||||||
|
<field name="currency"/>
|
||||||
|
<field name="unit"/>
|
||||||
</tree>
|
</tree>
|
||||||
Reference in New Issue
Block a user