diff --git a/modules/purchase_trade/lot.py b/modules/purchase_trade/lot.py
index 177e2a4..c8ac26c 100755
--- a/modules/purchase_trade/lot.py
+++ b/modules/purchase_trade/lot.py
@@ -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:
diff --git a/modules/purchase_trade/tests/test_module.py b/modules/purchase_trade/tests/test_module.py
index d193b65..522b999 100644
--- a/modules/purchase_trade/tests/test_module.py
+++ b/modules/purchase_trade/tests/test_module.py
@@ -2764,6 +2764,25 @@ class PurchaseTradeTestCase(ModuleTestCase):
patch.object(lot_module.LotQt, 'search', return_value=[]):
lot_module.LotQt.match_lots([purchase_lot], [])
+ def test_lot_matching_gauge_uses_entered_quantity_to_match(self):
+ 'go to matching gauge projects tolerance from qt to match'
+ matching_lot = lot_module.LotMatchingLot()
+ matching_lot.lot_theoretical_qt = Decimal('100')
+ matching_lot.lot_already_matched_qt = Decimal('40')
+ matching_lot.lot_matched_qt = Decimal('65')
+ matching_lot.lot_tol_min = Decimal('5')
+ matching_lot.lot_tol_max = Decimal('10')
+
+ self.assertEqual(
+ matching_lot.on_change_with_lot_tolerance_used(),
+ Decimal('5.00000'))
+ self.assertEqual(
+ matching_lot.on_change_with_lot_tolerance_min(),
+ Decimal('-5'))
+ self.assertEqual(
+ matching_lot.on_change_with_lot_tolerance_max(),
+ Decimal('10'))
+
def test_go_matching_defaults_selected_open_lot_qts(self):
'go to matching only preloads selected unmatched open lot.qt rows'
purchase = Mock(id=10, party=Mock(id=20))
diff --git a/modules/purchase_trade/view/lot_matching_lot_tree.xml b/modules/purchase_trade/view/lot_matching_lot_tree.xml
index 655bffc..d40f1b9 100755
--- a/modules/purchase_trade/view/lot_matching_lot_tree.xml
+++ b/modules/purchase_trade/view/lot_matching_lot_tree.xml
@@ -7,7 +7,14 @@
-
-
+
+
+
+
+
+
+
diff --git a/modules/purchase_trade/view/lot_matching_lot_tree2.xml b/modules/purchase_trade/view/lot_matching_lot_tree2.xml
index b19ce8f..165cdca 100755
--- a/modules/purchase_trade/view/lot_matching_lot_tree2.xml
+++ b/modules/purchase_trade/view/lot_matching_lot_tree2.xml
@@ -7,7 +7,14 @@
-
-
+
+
+
+
+
+
+
diff --git a/modules/purchase_trade/view/purchase_line_form.xml b/modules/purchase_trade/view/purchase_line_form.xml
index 993db6d..9a6caa5 100755
--- a/modules/purchase_trade/view/purchase_line_form.xml
+++ b/modules/purchase_trade/view/purchase_line_form.xml
@@ -44,7 +44,6 @@ this repository contains the full copyright notices and license terms. -->
-
-