Set button decorator for sending and updating invoices on Chorus to a different method than the cron
Closes #15069 (grafted from 59d049637f6755f0678f5acb460525b5be5d72b4) --HG-- branch : 8.0
This commit is contained in:
@@ -336,10 +336,21 @@ class InvoiceChorus(
|
||||
'company': self.invoice.company.id,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def send(cls, records=None):
|
||||
transaction = Transaction()
|
||||
if not records:
|
||||
records = cls.search([
|
||||
('invoice.company', '=',
|
||||
transaction.context.get('company')),
|
||||
('state', '=', 'draft'),
|
||||
])
|
||||
cls.send_button(records)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('sent')
|
||||
def send(cls, records=None):
|
||||
def send_button(cls, records=None):
|
||||
"""Send invoice to Chorus
|
||||
|
||||
The transaction is committed after each invoice.
|
||||
@@ -348,13 +359,6 @@ class InvoiceChorus(
|
||||
Credential = pool.get('account.credential.chorus')
|
||||
transaction = Transaction()
|
||||
|
||||
if not records:
|
||||
records = cls.search([
|
||||
('invoice.company', '=',
|
||||
transaction.context.get('company')),
|
||||
('state', '=', 'draft'),
|
||||
])
|
||||
|
||||
sessions = defaultdict(Credential.get_session)
|
||||
cls.lock(records)
|
||||
for record in records:
|
||||
@@ -392,11 +396,7 @@ class InvoiceChorus(
|
||||
}
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def update(cls, records=None):
|
||||
"Update state from Chorus"
|
||||
pool = Pool()
|
||||
Credential = pool.get('account.credential.chorus')
|
||||
transaction = Transaction()
|
||||
|
||||
if not records:
|
||||
@@ -405,6 +405,15 @@ class InvoiceChorus(
|
||||
transaction.context.get('company')),
|
||||
('state', '=', 'sent'),
|
||||
])
|
||||
cls.update_button(records)
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def update_button(cls, records=None):
|
||||
"Update state from Chorus"
|
||||
pool = Pool()
|
||||
Credential = pool.get('account.credential.chorus')
|
||||
transaction = Transaction()
|
||||
|
||||
sessions = defaultdict(Credential.get_session)
|
||||
succeeded, failed = [], []
|
||||
|
||||
@@ -123,7 +123,11 @@ Check Chorus invoice::
|
||||
|
||||
Send to Chorus::
|
||||
|
||||
>>> invoice_chorus.click('send')
|
||||
>>> invoice_send, = Cron.find(
|
||||
... [('method', '=', 'account.invoice.chorus|send')], limit=1)
|
||||
>>> invoice_send.click('run_once')
|
||||
|
||||
>>> invoice_chorus.reload()
|
||||
>>> invoice_chorus.state
|
||||
'sent'
|
||||
>>> bool(invoice_chorus.number)
|
||||
@@ -136,8 +140,11 @@ Send to Chorus::
|
||||
|
||||
Update from Chorus::
|
||||
|
||||
>>> invoice_update, = Cron.find(
|
||||
... [('method', '=', 'account.invoice.chorus|update')], limit=1)
|
||||
>>> while invoice_chorus.state == 'sent':
|
||||
... invoice_chorus.click('update')
|
||||
... invoice_update.click('run_once')
|
||||
... invoice_chorus.reload()
|
||||
... time.sleep(1)
|
||||
>>> invoice_chorus.state
|
||||
'exception'
|
||||
|
||||
Reference in New Issue
Block a user