mirror of
https://gitlab.com/datalifeit/trytond-account_bank
synced 2023-12-14 06:23:07 +01:00
Set bank_account field on invoice creation if it was not already set.
This commit is contained in:
parent
03f15d401a
commit
4a56d3d702
1 changed files with 22 additions and 3 deletions
25
account.py
25
account.py
|
@ -69,7 +69,8 @@ class Invoice:
|
||||||
company = Transaction().context.get('company', False)
|
company = Transaction().context.get('company', False)
|
||||||
return Company(company).party.id
|
return Company(company).party.id
|
||||||
|
|
||||||
def _get_bank_account(self, payment_type, party, company):
|
@classmethod
|
||||||
|
def _get_bank_account(cls, payment_type, party, company):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Company = pool.get('company.company')
|
Company = pool.get('company.company')
|
||||||
Party = pool.get('party.party')
|
Party = pool.get('party.party')
|
||||||
|
@ -81,7 +82,7 @@ class Invoice:
|
||||||
if default_bank:
|
if default_bank:
|
||||||
return default_bank.id
|
return default_bank.id
|
||||||
else:
|
else:
|
||||||
self.raise_user_error('party_without_bank_account',
|
cls.raise_user_error('party_without_bank_account',
|
||||||
(party.name, payment_type.kind))
|
(party.name, payment_type.kind))
|
||||||
elif account_bank == 'company' and company:
|
elif account_bank == 'company' and company:
|
||||||
party = Company(company).party
|
party = Company(company).party
|
||||||
|
@ -90,7 +91,7 @@ class Invoice:
|
||||||
if default_bank:
|
if default_bank:
|
||||||
return default_bank.id
|
return default_bank.id
|
||||||
else:
|
else:
|
||||||
self.raise_user_error('party_without_bank_account',
|
cls.raise_user_error('party_without_bank_account',
|
||||||
(party.name, payment_type.kind))
|
(party.name, payment_type.kind))
|
||||||
|
|
||||||
def on_change_payment_type(self):
|
def on_change_payment_type(self):
|
||||||
|
@ -131,6 +132,24 @@ class Invoice:
|
||||||
res['bank_account'] = self.bank_account
|
res['bank_account'] = self.bank_account
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create(cls, vlist):
|
||||||
|
pool = Pool()
|
||||||
|
PaymentType = pool.get('account.payment.type')
|
||||||
|
Party = pool.get('party.party')
|
||||||
|
Company = pool.get('company.company')
|
||||||
|
vlist = [x.copy() for x in vlist]
|
||||||
|
for values in vlist:
|
||||||
|
if (not 'bank_account' in values and 'payment_type' in values
|
||||||
|
and 'party' in values):
|
||||||
|
party = Party(values['party'])
|
||||||
|
company = Company(values.get('company',
|
||||||
|
Transaction().context.get('company'))).party
|
||||||
|
payment_type = PaymentType(values['payment_type'])
|
||||||
|
values['bank_account'] = cls._get_bank_account(payment_type,
|
||||||
|
party, company)
|
||||||
|
return super(Invoice, cls).create(vlist)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ModelView.button
|
@ModelView.button
|
||||||
@Workflow.transition('posted')
|
@Workflow.transition('posted')
|
||||||
|
|
Loading…
Reference in a new issue