Jauges Go to matching
This commit is contained in:
@@ -1250,6 +1250,7 @@ class LotQt(
|
||||
tol_min = cls._matching_line_tolerance_percent(line, 'tol_min')
|
||||
tol_max = cls._matching_line_tolerance_percent(line, 'tol_max')
|
||||
return {
|
||||
'lot_theoretical_qt': theoretical,
|
||||
'lot_tol_min': tol_min,
|
||||
'lot_tol_max': tol_max,
|
||||
'lot_qt_min': round(
|
||||
@@ -1296,6 +1297,21 @@ class LotQt(
|
||||
tolerated_available = Decimal(str(qt_max)) - matched
|
||||
return max(available, tolerated_available, Decimal(0))
|
||||
|
||||
@classmethod
|
||||
def _matching_already_matched(cls, lqt, side):
|
||||
line = cls._matching_line(lqt, side)
|
||||
if not line:
|
||||
return Decimal(0)
|
||||
if side == 'purchase':
|
||||
domain = [('lot_p', '=', getattr(lqt.lot_p, 'id', lqt.lot_p)),
|
||||
('lot_s', '>', 0)]
|
||||
else:
|
||||
domain = [('lot_p', '>', 0),
|
||||
('lot_s', '=', getattr(lqt.lot_s, 'id', lqt.lot_s))]
|
||||
return sum(
|
||||
cls._matching_quantity_in_line_unit(matched_lqt, line)
|
||||
for matched_lqt in cls.search(domain))
|
||||
|
||||
@classmethod
|
||||
def match_lots(cls,lot_p,lot_s):
|
||||
logger.info("MATCH_LOTS:%s",lot_p)
|
||||
@@ -2908,6 +2924,8 @@ class LotMatching(Wizard):
|
||||
'lot_product': cls._record_id(getattr(lot, 'lot_product', None)),
|
||||
'lot_quantity': quantity,
|
||||
'lot_matched_qt': 0,
|
||||
'lot_already_matched_qt': LotQt._matching_already_matched(
|
||||
lqt, side),
|
||||
'lot_cp': cls._record_id(party),
|
||||
}
|
||||
trade_line = line if side == 'purchase' else sale_line
|
||||
@@ -3079,6 +3097,8 @@ class LotMatchingStart(ModelView):
|
||||
val['lot_matched_qt'] = 0
|
||||
val['lot_cp'] = r['r_client']
|
||||
lqt = LotQt(r['id'] - 10000000)
|
||||
val['lot_already_matched_qt'] = (
|
||||
LotQt._matching_already_matched(lqt, 'sale'))
|
||||
val.update(LotQt._matching_line_tolerance_info(
|
||||
LotQt._matching_line(lqt, 'sale')))
|
||||
lp.append(val)
|
||||
@@ -3107,6 +3127,8 @@ class LotMatchingStart(ModelView):
|
||||
val['lot_matched_qt'] = 0
|
||||
val['lot_cp'] = r['r_supplier']
|
||||
lqt = LotQt(r['id'] - 10000000)
|
||||
val['lot_already_matched_qt'] = (
|
||||
LotQt._matching_already_matched(lqt, 'purchase'))
|
||||
val.update(LotQt._matching_line_tolerance_info(
|
||||
LotQt._matching_line(lqt, 'purchase')))
|
||||
lp.append(val)
|
||||
@@ -3132,10 +3154,18 @@ class LotMatchingLot(ModelView):
|
||||
lot_shipment_out = fields.Many2One('stock.shipment.out',"Shipment Out")
|
||||
lot_product = fields.Many2One('product.product',"Product",readonly=True)
|
||||
lot_quantity = fields.Numeric("Qt",readonly=True)
|
||||
lot_theoretical_qt = fields.Numeric("Theoretical Qt", readonly=True)
|
||||
lot_already_matched_qt = fields.Numeric("Already matched", readonly=True)
|
||||
lot_qt_min = fields.Numeric("Qt min", readonly=True)
|
||||
lot_qt_max = fields.Numeric("Qt max", readonly=True)
|
||||
lot_tol_min = fields.Numeric("Tol -", readonly=True)
|
||||
lot_tol_max = fields.Numeric("Tol +", readonly=True)
|
||||
lot_tolerance_used = fields.Function(
|
||||
fields.Numeric("Tolerance used"), 'on_change_with_lot_tolerance_used')
|
||||
lot_tolerance_min = fields.Function(
|
||||
fields.Numeric("Tolerance min"), 'on_change_with_lot_tolerance_min')
|
||||
lot_tolerance_max = fields.Function(
|
||||
fields.Numeric("Tolerance max"), 'on_change_with_lot_tolerance_max')
|
||||
lot_unit = fields.Many2One('product.uom',"Unit",readonly=True)
|
||||
lot_matched_qt = fields.Numeric("Qt to match")
|
||||
lot_cp = fields.Many2One('party.party',"Counterparty")
|
||||
@@ -3148,10 +3178,30 @@ class LotMatchingLot(ModelView):
|
||||
],
|
||||
string="Shipment",
|
||||
),
|
||||
"get_shipment_origin",
|
||||
)
|
||||
|
||||
def get_shipment_origin(self, name):
|
||||
"get_shipment_origin",
|
||||
)
|
||||
|
||||
@fields.depends(
|
||||
'lot_matched_qt', 'lot_already_matched_qt', 'lot_theoretical_qt')
|
||||
def on_change_with_lot_tolerance_used(self, name=None):
|
||||
theoretical = Decimal(str(self.lot_theoretical_qt or 0))
|
||||
if not theoretical:
|
||||
return Decimal(0)
|
||||
projected = (
|
||||
Decimal(str(self.lot_already_matched_qt or 0))
|
||||
+ Decimal(str(self.lot_matched_qt or 0)))
|
||||
return round(
|
||||
((projected - theoretical) / theoretical) * Decimal(100), 5)
|
||||
|
||||
@fields.depends('lot_tol_min')
|
||||
def on_change_with_lot_tolerance_min(self, name=None):
|
||||
return -Decimal(str(self.lot_tol_min or 0))
|
||||
|
||||
@fields.depends('lot_tol_max')
|
||||
def on_change_with_lot_tolerance_max(self, name=None):
|
||||
return Decimal(str(self.lot_tol_max or 0))
|
||||
|
||||
def get_shipment_origin(self, name):
|
||||
if self.lot_shipment_in:
|
||||
return 'stock.shipment.in,' + str(self.lot_shipment_in.id)
|
||||
elif self.lot_shipment_out:
|
||||
|
||||
Reference in New Issue
Block a user