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 None, None, None, None
|
||||
|
||||
def get_alf(self):
|
||||
if self.name == 'CARGO CONTROL':
|
||||
return 105
|
||||
def get_alf(self):
|
||||
if self.name == 'CARGO CONTROL':
|
||||
return 105
|
||||
t = Table('alf')
|
||||
cursor = Transaction().connection.cursor()
|
||||
cursor.execute(*t.select(
|
||||
@@ -158,27 +158,41 @@ class Party(metaclass=PoolMeta):
|
||||
where=t.SHORT_NAME.ilike(f'%{self.name}%')
|
||||
))
|
||||
rows = cursor.fetchall()
|
||||
if rows:
|
||||
return int(rows[0][0])
|
||||
|
||||
@classmethod
|
||||
def getPartyByName(cls, party, category=None):
|
||||
party = party.upper()
|
||||
p = cls.search([('name', '=', party)], limit=1)
|
||||
if p:
|
||||
return p[0]
|
||||
else:
|
||||
p = cls()
|
||||
p.name = party
|
||||
cls.save([p])
|
||||
if category:
|
||||
Category = Pool().get('party.category')
|
||||
cat = Category.search(['name','=',category])
|
||||
if cat:
|
||||
PartyCategory = Pool().get('party.party-party.category')
|
||||
pc = PartyCategory()
|
||||
pc.party = p.id
|
||||
pc.category = cat[0].id
|
||||
PartyCategory.save([pc])
|
||||
return p
|
||||
if rows:
|
||||
return int(rows[0][0])
|
||||
|
||||
@classmethod
|
||||
def _ensure_category(cls, party, category_name):
|
||||
if not (party and category_name):
|
||||
return
|
||||
Category = Pool().get('party.category')
|
||||
PartyCategory = Pool().get('party.party-party.category')
|
||||
cat = Category.search(['name', '=', category_name], limit=1)
|
||||
if not cat:
|
||||
return
|
||||
cat = cat[0]
|
||||
existing = PartyCategory.search([
|
||||
('party', '=', party.id),
|
||||
('category', '=', cat.id),
|
||||
], limit=1)
|
||||
if existing:
|
||||
return
|
||||
pc = PartyCategory()
|
||||
pc.party = party.id
|
||||
pc.category = cat.id
|
||||
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()),
|
||||
(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):
|
||||
'shipment fee creation skips cleanly when controller has no matching sla'
|
||||
ShipmentIn = Pool().get('stock.shipment.in')
|
||||
|
||||
Reference in New Issue
Block a user