cron faircot
This commit is contained in:
@@ -141,11 +141,12 @@ class Party(metaclass=PoolMeta):
|
|||||||
|
|
||||||
def get_sla_cost(self,location):
|
def get_sla_cost(self,location):
|
||||||
if self.sla:
|
if self.sla:
|
||||||
for sla in self.sla:
|
for sla in self.sla:
|
||||||
SlaPlace = Pool().get('party.execution.place')
|
SlaPlace = Pool().get('party.execution.place')
|
||||||
sp = SlaPlace.search([('pes','=', sla.id),('location','=',location)])
|
sp = SlaPlace.search([('pes','=', sla.id),('location','=',location)])
|
||||||
if sp:
|
if sp:
|
||||||
return sp[0].cost,sp[0].mode,sp[0].currency,sp[0].unit
|
return sp[0].cost,sp[0].mode,sp[0].currency,sp[0].unit
|
||||||
|
return None, None, None, None
|
||||||
|
|
||||||
def get_alf(self):
|
def get_alf(self):
|
||||||
if self.name == 'CARGO CONTROL':
|
if self.name == 'CARGO CONTROL':
|
||||||
|
|||||||
@@ -799,23 +799,30 @@ class ShipmentIn(metaclass=PoolMeta):
|
|||||||
else:
|
else:
|
||||||
return str(self.id)
|
return str(self.id)
|
||||||
|
|
||||||
def create_fee(self,controller):
|
def create_fee(self,controller):
|
||||||
Fee = Pool().get('fee.fee')
|
Fee = Pool().get('fee.fee')
|
||||||
Product = Pool().get('product.product')
|
Product = Pool().get('product.product')
|
||||||
fee = Fee()
|
if not controller:
|
||||||
fee.shipment_in = self.id
|
logger.info("CREATE_FEE_SKIPPED:NO_CONTROLLER shipment=%s", self)
|
||||||
fee.supplier = controller
|
return
|
||||||
fee.type = 'budgeted'
|
fee = Fee()
|
||||||
fee.p_r = 'pay'
|
fee.shipment_in = self.id
|
||||||
price,mode,curr,unit = controller.get_sla_cost(self.to_location)
|
fee.supplier = controller
|
||||||
if price and mode and curr and unit:
|
fee.type = 'budgeted'
|
||||||
fee.mode = mode
|
fee.p_r = 'pay'
|
||||||
fee.currency = curr
|
price,mode,curr,unit = controller.get_sla_cost(self.to_location)
|
||||||
fee.unit = unit
|
if not (price and mode and curr and unit):
|
||||||
fee.quantity = self.get_bales() or 1
|
logger.info(
|
||||||
fee.product = Product.get_by_name('Reweighing')
|
"CREATE_FEE_SKIPPED:NO_SLA shipment=%s controller=%s location=%s",
|
||||||
fee.price = price
|
self, controller, self.to_location)
|
||||||
Fee.save([fee])
|
return
|
||||||
|
fee.mode = mode
|
||||||
|
fee.currency = curr
|
||||||
|
fee.unit = unit
|
||||||
|
fee.quantity = self.get_bales() or 1
|
||||||
|
fee.product = Product.get_by_name('Reweighing')
|
||||||
|
fee.price = price
|
||||||
|
Fee.save([fee])
|
||||||
|
|
||||||
def get_controller(self):
|
def get_controller(self):
|
||||||
ControllerCategory = Pool().get('party.category')
|
ControllerCategory = Pool().get('party.category')
|
||||||
|
|||||||
@@ -269,6 +269,40 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
|||||||
|
|
||||||
self.assertEqual(line._get_linked_unit_factor(), Decimal('2'))
|
self.assertEqual(line._get_linked_unit_factor(), Decimal('2'))
|
||||||
|
|
||||||
|
def test_get_sla_cost_returns_empty_tuple_when_no_place_matches(self):
|
||||||
|
'controller sla helper keeps a stable tuple contract when no sla rule matches'
|
||||||
|
Party = Pool().get('party.party')
|
||||||
|
party = Party()
|
||||||
|
party.sla = []
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
party.get_sla_cost(Mock()),
|
||||||
|
(None, None, None, None))
|
||||||
|
|
||||||
|
def test_create_fee_skips_when_controller_has_no_sla_cost(self):
|
||||||
|
'shipment fee creation skips cleanly when controller has no matching sla'
|
||||||
|
ShipmentIn = Pool().get('stock.shipment.in')
|
||||||
|
shipment = ShipmentIn()
|
||||||
|
shipment.id = 99
|
||||||
|
shipment.to_location = Mock()
|
||||||
|
shipment.get_bales = Mock(return_value=Decimal('10'))
|
||||||
|
controller = Mock()
|
||||||
|
controller.get_sla_cost.return_value = (None, None, None, None)
|
||||||
|
|
||||||
|
fee_model = Mock()
|
||||||
|
product_model = Mock()
|
||||||
|
|
||||||
|
with patch('trytond.modules.purchase_trade.stock.Pool') as PoolMock:
|
||||||
|
PoolMock.return_value.get.side_effect = lambda name: {
|
||||||
|
'fee.fee': fee_model,
|
||||||
|
'product.product': product_model,
|
||||||
|
}[name]
|
||||||
|
|
||||||
|
shipment.create_fee(controller)
|
||||||
|
|
||||||
|
fee_model.save.assert_not_called()
|
||||||
|
product_model.get_by_name.assert_not_called()
|
||||||
|
|
||||||
def test_purchase_line_default_pricing_rule_comes_from_configuration(self):
|
def test_purchase_line_default_pricing_rule_comes_from_configuration(self):
|
||||||
'purchase line pricing_rule defaults to the purchase_trade singleton value'
|
'purchase line pricing_rule defaults to the purchase_trade singleton value'
|
||||||
PurchaseLine = Pool().get('purchase.line')
|
PurchaseLine = Pool().get('purchase.line')
|
||||||
|
|||||||
Reference in New Issue
Block a user