price component
This commit is contained in:
@@ -1240,11 +1240,15 @@ class Line(metaclass=PoolMeta):
|
||||
if self.tol_max and self.quantity_theorical:
|
||||
return round((1+(self.tol_max/100))*Decimal(self.quantity_theorical),3)
|
||||
|
||||
def get_progress(self,name):
|
||||
PS = Pool().get('purchase.pricing.summary')
|
||||
ps = PS.search(['line','=',self.id])
|
||||
if ps:
|
||||
return sum((e.progress if e.progress else 0) * (e.ratio if e.ratio else 0) / 100 for e in ps)
|
||||
def get_progress(self,name):
|
||||
PS = Pool().get('purchase.pricing.summary')
|
||||
ps = PS.search(['line','=',self.id])
|
||||
if ps:
|
||||
if not self.price_components:
|
||||
manual = [e for e in ps if not e.price_component]
|
||||
if manual:
|
||||
return manual[0].progress or 0
|
||||
return sum((e.progress if e.progress else 0) * (e.ratio if e.ratio else 0) / 100 for e in ps)
|
||||
|
||||
def getVirtualLot(self):
|
||||
if self.lots:
|
||||
@@ -1296,8 +1300,16 @@ class Line(metaclass=PoolMeta):
|
||||
for t in self.terms:
|
||||
price += (t.manual_price if t.manual_price else Decimal(0))
|
||||
else:
|
||||
for pc in self.price_components:
|
||||
PP = Pool().get('purchase.pricing.summary')
|
||||
if not self.price_components:
|
||||
PP = Pool().get('purchase.pricing.summary')
|
||||
pp = PP.search([
|
||||
('line', '=', self.id),
|
||||
('price_component', '=', None),
|
||||
], limit=1)
|
||||
if pp:
|
||||
return round(Decimal(pp[0].price or 0), 4)
|
||||
for pc in self.price_components:
|
||||
PP = Pool().get('purchase.pricing.summary')
|
||||
pp = PP.search([('price_component','=',pc.id),('line','=',self.id)])
|
||||
if pp:
|
||||
price += pp[0].price * (pc.ratio / 100)
|
||||
|
||||
@@ -1167,11 +1167,15 @@ class SaleLine(metaclass=PoolMeta):
|
||||
if self.tol_max and self.quantity_theorical:
|
||||
return round((1+(self.tol_max/100))*Decimal(self.quantity_theorical),3)
|
||||
|
||||
def get_progress(self,name):
|
||||
PS = Pool().get('sale.pricing.summary')
|
||||
ps = PS.search(['sale_line','=',self.id])
|
||||
if ps:
|
||||
return sum((e.progress if e.progress else 0) * (e.ratio if e.ratio else 0) / 100 for e in ps)
|
||||
def get_progress(self,name):
|
||||
PS = Pool().get('sale.pricing.summary')
|
||||
ps = PS.search(['sale_line','=',self.id])
|
||||
if ps:
|
||||
if not self.price_components:
|
||||
manual = [e for e in ps if not e.price_component]
|
||||
if manual:
|
||||
return manual[0].progress or 0
|
||||
return sum((e.progress if e.progress else 0) * (e.ratio if e.ratio else 0) / 100 for e in ps)
|
||||
|
||||
def getVirtualLot(self):
|
||||
if self.lots:
|
||||
@@ -1225,6 +1229,14 @@ class SaleLine(metaclass=PoolMeta):
|
||||
|
||||
def _get_basis_component_price(self):
|
||||
price = Decimal(0)
|
||||
if not self.price_components:
|
||||
PP = Pool().get('sale.pricing.summary')
|
||||
pp = PP.search([
|
||||
('sale_line', '=', self.id),
|
||||
('price_component', '=', None),
|
||||
], limit=1)
|
||||
if pp:
|
||||
return round(Decimal(pp[0].price or 0), 4)
|
||||
for pc in self.price_components:
|
||||
PP = Pool().get('sale.pricing.summary')
|
||||
pp = PP.search([('price_component','=',pc.id),('sale_line','=',self.id)])
|
||||
|
||||
@@ -336,6 +336,51 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertEqual(
|
||||
Purchase.operator.domain, [('categories.name', '=', 'OPERATOR')])
|
||||
|
||||
def test_sale_line_basis_price_and_progress_use_manual_summary_without_component(self):
|
||||
'sale line basis values use manual summary rows even without a component'
|
||||
SaleLine = Pool().get('sale.line')
|
||||
summary_model = Mock()
|
||||
summary_model.search.side_effect = [
|
||||
[Mock(price=Decimal('150'), progress=1, price_component=None)],
|
||||
[Mock(price=Decimal('150'), progress=1, price_component=None)],
|
||||
]
|
||||
|
||||
line = SaleLine()
|
||||
line.id = 1
|
||||
line.price_type = 'basis'
|
||||
line.price_components = []
|
||||
line.enable_linked_currency = False
|
||||
line.linked_currency = None
|
||||
|
||||
with patch('trytond.modules.purchase_trade.sale.Pool') as PoolMock:
|
||||
PoolMock.return_value.get.return_value = summary_model
|
||||
|
||||
self.assertEqual(line.get_basis_price(), Decimal('150.0000'))
|
||||
self.assertEqual(line.get_progress('progress'), 1)
|
||||
|
||||
def test_purchase_line_basis_price_and_progress_use_manual_summary_without_component(self):
|
||||
'purchase line basis values use manual summary rows even without a component'
|
||||
PurchaseLine = Pool().get('purchase.line')
|
||||
summary_model = Mock()
|
||||
summary_model.search.side_effect = [
|
||||
[Mock(price=Decimal('150'), progress=1, price_component=None)],
|
||||
[Mock(price=Decimal('150'), progress=1, price_component=None)],
|
||||
]
|
||||
|
||||
line = PurchaseLine()
|
||||
line.id = 1
|
||||
line.price_type = 'basis'
|
||||
line.price_components = []
|
||||
line.terms = []
|
||||
line.enable_linked_currency = False
|
||||
line.linked_currency = None
|
||||
|
||||
with patch('trytond.modules.purchase_trade.purchase.Pool') as PoolMock:
|
||||
PoolMock.return_value.get.return_value = summary_model
|
||||
|
||||
self.assertEqual(line.get_basis_price(), Decimal('150.0000'))
|
||||
self.assertEqual(line.get_progress('progress'), 1)
|
||||
|
||||
def test_sale_line_write_updates_virtual_lot_when_theorical_qty_increases(self):
|
||||
'sale line write increases virtual lot and open lot.qt when contractual qty grows'
|
||||
SaleLine = Pool().get('sale.line')
|
||||
|
||||
Reference in New Issue
Block a user