cron faircot
This commit is contained in:
@@ -148,9 +148,9 @@ class Party(metaclass=PoolMeta):
|
|||||||
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
|
return None, None, None, None
|
||||||
|
|
||||||
def get_alf(self):
|
def get_alf(self):
|
||||||
if self.name == 'CARGO CONTROL':
|
if self.name == 'CARGO CONTROL':
|
||||||
return 105
|
return 105
|
||||||
t = Table('alf')
|
t = Table('alf')
|
||||||
cursor = Transaction().connection.cursor()
|
cursor = Transaction().connection.cursor()
|
||||||
cursor.execute(*t.select(
|
cursor.execute(*t.select(
|
||||||
@@ -158,27 +158,41 @@ class Party(metaclass=PoolMeta):
|
|||||||
where=t.SHORT_NAME.ilike(f'%{self.name}%')
|
where=t.SHORT_NAME.ilike(f'%{self.name}%')
|
||||||
))
|
))
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
if rows:
|
if rows:
|
||||||
return int(rows[0][0])
|
return int(rows[0][0])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getPartyByName(cls, party, category=None):
|
def _ensure_category(cls, party, category_name):
|
||||||
party = party.upper()
|
if not (party and category_name):
|
||||||
p = cls.search([('name', '=', party)], limit=1)
|
return
|
||||||
if p:
|
Category = Pool().get('party.category')
|
||||||
return p[0]
|
PartyCategory = Pool().get('party.party-party.category')
|
||||||
else:
|
cat = Category.search(['name', '=', category_name], limit=1)
|
||||||
p = cls()
|
if not cat:
|
||||||
p.name = party
|
return
|
||||||
cls.save([p])
|
cat = cat[0]
|
||||||
if category:
|
existing = PartyCategory.search([
|
||||||
Category = Pool().get('party.category')
|
('party', '=', party.id),
|
||||||
cat = Category.search(['name','=',category])
|
('category', '=', cat.id),
|
||||||
if cat:
|
], limit=1)
|
||||||
PartyCategory = Pool().get('party.party-party.category')
|
if existing:
|
||||||
pc = PartyCategory()
|
return
|
||||||
pc.party = p.id
|
pc = PartyCategory()
|
||||||
pc.category = cat[0].id
|
pc.party = party.id
|
||||||
PartyCategory.save([pc])
|
pc.category = cat.id
|
||||||
return p
|
PartyCategory.save([pc])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getPartyByName(cls, party, category=None):
|
||||||
|
party = party.upper()
|
||||||
|
p = cls.search([('name', '=', party)], limit=1)
|
||||||
|
if p:
|
||||||
|
cls._ensure_category(p[0], category)
|
||||||
|
return p[0]
|
||||||
|
else:
|
||||||
|
p = cls()
|
||||||
|
p.name = party
|
||||||
|
cls.save([p])
|
||||||
|
cls._ensure_category(p, category)
|
||||||
|
return p
|
||||||
|
|
||||||
|
|||||||
@@ -279,6 +279,28 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
|||||||
party.get_sla_cost(Mock()),
|
party.get_sla_cost(Mock()),
|
||||||
(None, None, None, None))
|
(None, None, None, None))
|
||||||
|
|
||||||
|
def test_get_party_by_name_adds_missing_category_to_existing_party(self):
|
||||||
|
'existing parties found by automation gain the requested category when missing'
|
||||||
|
Party = Pool().get('party.party')
|
||||||
|
existing_party = Mock(id=12)
|
||||||
|
category = Mock(id=34)
|
||||||
|
category_model = Mock()
|
||||||
|
category_model.search.return_value = [category]
|
||||||
|
party_category_model = Mock()
|
||||||
|
party_category_model.search.return_value = []
|
||||||
|
|
||||||
|
with patch.object(Party, 'search', return_value=[existing_party]), patch(
|
||||||
|
'trytond.modules.purchase_trade.party.Pool') as PoolMock:
|
||||||
|
PoolMock.return_value.get.side_effect = lambda name: {
|
||||||
|
'party.category': category_model,
|
||||||
|
'party.party-party.category': party_category_model,
|
||||||
|
}[name]
|
||||||
|
|
||||||
|
party = Party.getPartyByName('SYED SP COT D BD', 'CLIENT')
|
||||||
|
|
||||||
|
self.assertIs(party, existing_party)
|
||||||
|
party_category_model.save.assert_called_once()
|
||||||
|
|
||||||
def test_create_fee_skips_when_controller_has_no_sla_cost(self):
|
def test_create_fee_skips_when_controller_has_no_sla_cost(self):
|
||||||
'shipment fee creation skips cleanly when controller has no matching sla'
|
'shipment fee creation skips cleanly when controller has no matching sla'
|
||||||
ShipmentIn = Pool().get('stock.shipment.in')
|
ShipmentIn = Pool().get('stock.shipment.in')
|
||||||
|
|||||||
Reference in New Issue
Block a user