This commit is contained in:
2026-02-05 17:06:00 +01:00
parent 91f85ea7c1
commit 00a6a5debe

View File

@@ -6,7 +6,7 @@ from trytond.pyson import Bool, Eval, Id, If
from trytond.model import (ModelSQL, ModelView) from trytond.model import (ModelSQL, ModelView)
from trytond.tools import is_full_text, lstrip_wildcard from trytond.tools import is_full_text, lstrip_wildcard
from trytond.transaction import Transaction, inactive_records from trytond.transaction import Transaction, inactive_records
from decimal import getcontext, Decimal, ROUND_HALF_UP from decimal import getcontext, Decimal, ROUND_UP, ROUND_HALF_UP
from sql.aggregate import Count, Max, Min, Sum, Avg, BoolOr from sql.aggregate import Count, Max, Min, Sum, Avg, BoolOr
from sql.conditionals import Case from sql.conditionals import Case
from sql import Column, Literal from sql import Column, Literal
@@ -103,12 +103,14 @@ class Fee(ModelSQL,ModelView):
@fields.depends('unit','auto_calculation','mode','_parent_line.unit','_parent_line.lots','_parent_sale_line.unit','_parent_sale_line.lots','_parent_shipment_in.id') @fields.depends('unit','auto_calculation','mode','_parent_line.unit','_parent_line.lots','_parent_sale_line.unit','_parent_sale_line.lots','_parent_shipment_in.id')
def on_change_with_quantity(self, name=None): def on_change_with_quantity(self, name=None):
qt = None qt = None
unit = None
line = self.line line = self.line
if not line: if not line:
line = self.sale_line line = self.sale_line
if line: if line:
if line.lots: if line.lots:
qt = sum([e.get_current_quantity() for e in line.lots]) qt = sum([e.get_current_quantity() for e in line.lots])
unit = line.lots[0].lot_unit_line
logger.info("ON_CHANGE_WITH_QT0:%s",qt) logger.info("ON_CHANGE_WITH_QT0:%s",qt)
if not qt: if not qt:
logger.info("ON_CHANGE_WITH_QT1:%s",qt) logger.info("ON_CHANGE_WITH_QT1:%s",qt)
@@ -116,12 +118,13 @@ class Fee(ModelSQL,ModelView):
lqts = LotQt.search(['lot_shipment_in','=',self.shipment_in.id]) lqts = LotQt.search(['lot_shipment_in','=',self.shipment_in.id])
if lqts: if lqts:
qt = Decimal(lqts[0].lot_quantity) qt = Decimal(lqts[0].lot_quantity)
unit = lqts[0].lot_unit
logger.info("ON_CHANGE_WITH_QT2:%s",qt) logger.info("ON_CHANGE_WITH_QT2:%s",qt)
if self.mode != 'ppack': if self.mode != 'ppack':
return qt return qt
else: else:
if self.auto_calculation: if self.auto_calculation:
return Decimal(int(qt/Decimal(self.unit.factor))) return (qt * unit.factor / Decimal(self.unit.factor)).to_integral_value(rounding=ROUND_UP)
@fields.depends('mode','_parent_line.lots','_parent_sale_line.lots') @fields.depends('mode','_parent_line.lots','_parent_sale_line.lots')
def on_change_with_unit(self, name=None): def on_change_with_unit(self, name=None):