Bug Add Physical
This commit is contained in:
@@ -1645,14 +1645,14 @@ class LotQt(
|
||||
newlot.lot_shipment_internal = self.lot_shipment_internal
|
||||
newlot.lot_shipment_out = self.lot_shipment_out
|
||||
newlot.lot_product = self.lot_p.line.product
|
||||
newlot.lot_chunk_key = l.lot_chunk_key
|
||||
newlot.lot_chunk_key = getattr(l, 'lot_chunk_key', None)
|
||||
if self.lot_s:
|
||||
newlot.sale_line = self.lot_s.sale_line if self.lot_s.sale_line else None
|
||||
newlot.lot_type = 'physic'
|
||||
newlot.lot_qt = l.lot_qt
|
||||
newlot.lot_unit = l.lot_unit
|
||||
newlot.lot_unit_line = l.lot_unit_line
|
||||
newlot.lot_premium = l.lot_premium
|
||||
newlot.lot_premium = getattr(l, 'lot_premium', None) or Decimal(0)
|
||||
if newlot.lot_shipment_in or newlot.lot_shipment_internal or newlot.lot_shipment_out:
|
||||
newlot.lot_status = 'transit'
|
||||
newlot.set_current_quantity(l.lot_quantity,l.lot_gross_quantity,1)
|
||||
|
||||
@@ -80,6 +80,58 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
strategy.get_mtm(line, Decimal('10')),
|
||||
Decimal('250.00'))
|
||||
|
||||
@with_transaction()
|
||||
def test_add_physical_lot_defaults_hidden_premium_and_chunk_key(self):
|
||||
'add physical lot works when hidden tree fields are not loaded'
|
||||
LotQt = Pool().get('lot.qt')
|
||||
saved_lots = []
|
||||
|
||||
class FakeLot:
|
||||
def __init__(self):
|
||||
self.sale_line = None
|
||||
self.id = 1
|
||||
|
||||
def set_current_quantity(self, quantity, gross_quantity, type_):
|
||||
self.quantity = quantity
|
||||
self.gross_quantity = gross_quantity
|
||||
self.quantity_type = type_
|
||||
|
||||
def get_current_quantity_converted(self):
|
||||
return self.quantity
|
||||
|
||||
@classmethod
|
||||
def save(cls, lots):
|
||||
saved_lots.extend(lots)
|
||||
|
||||
class AddLine:
|
||||
lot_qt = Decimal('10')
|
||||
lot_unit = Mock()
|
||||
lot_unit_line = Mock()
|
||||
lot_quantity = Decimal('10')
|
||||
lot_gross_quantity = Decimal('11')
|
||||
|
||||
line = Mock(product=Mock(), fees=[])
|
||||
line.purchase = Mock()
|
||||
lqt = LotQt()
|
||||
lqt.lot_p = Mock(line=line)
|
||||
lqt.lot_s = None
|
||||
lqt.lot_shipment_in = None
|
||||
lqt.lot_shipment_internal = None
|
||||
lqt.lot_shipment_out = None
|
||||
|
||||
with patch('trytond.modules.purchase_trade.lot.Pool') as PoolMock:
|
||||
PoolMock.return_value.get.side_effect = lambda name: {
|
||||
'lot.lot': FakeLot,
|
||||
'fee.lots': Mock(),
|
||||
'purchase.purchase': Mock(),
|
||||
}[name]
|
||||
|
||||
lqt.add_physical_lot(AddLine())
|
||||
|
||||
self.assertEqual(len(saved_lots), 1)
|
||||
self.assertIsNone(saved_lots[0].lot_chunk_key)
|
||||
self.assertEqual(saved_lots[0].lot_premium, Decimal(0))
|
||||
|
||||
def test_get_strategy_mtm_price_applies_component_ratio(self):
|
||||
'strategy mtm price applies component ratios'
|
||||
strategy = Mock(
|
||||
|
||||
Reference in New Issue
Block a user