Refactor of the workoflow_to_end method to allow to modify in another modules when
the invoices has to be posted.
This commit is contained in:
parent
bcf5d9cabe
commit
e5102dd948
68
sale.py
68
sale.py
@ -48,7 +48,7 @@ class Sale(metaclass=PoolMeta):
|
|||||||
user = User(Transaction().user)
|
user = User(Transaction().user)
|
||||||
return user.sale_device and user.sale_device.id or None
|
return user.sale_device and user.sale_device.id or None
|
||||||
|
|
||||||
def set_values_to_invoice(self, invoice):
|
def set_basic_values_to_invoice(self, invoice):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Date = pool.get('ir.date')
|
Date = pool.get('ir.date')
|
||||||
today = Date.today()
|
today = Date.today()
|
||||||
@ -59,13 +59,32 @@ class Sale(metaclass=PoolMeta):
|
|||||||
invoice.description = self.reference
|
invoice.description = self.reference
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def workflow_to_end(cls, sales):
|
def set_invoices_to_be_posted(cls, sales):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Invoice = pool.get('account.invoice')
|
Invoice = pool.get('account.invoice')
|
||||||
StatementLine = pool.get('account.statement.line')
|
|
||||||
|
|
||||||
invoices = []
|
invoices = []
|
||||||
to_post = set()
|
to_post = set()
|
||||||
|
for sale in sales:
|
||||||
|
grouping = getattr(sale.party, 'sale_invoice_grouping_method',
|
||||||
|
False)
|
||||||
|
if getattr(sale, 'invoices', None) and not grouping:
|
||||||
|
for invoice in sale.invoices:
|
||||||
|
if not invoice.state == 'draft':
|
||||||
|
continue
|
||||||
|
sale.set_basic_values_to_invoice(invoice)
|
||||||
|
invoices.extend(([invoice], invoice._save_values))
|
||||||
|
to_post.add(invoice)
|
||||||
|
|
||||||
|
if to_post:
|
||||||
|
Invoice.write(*invoices)
|
||||||
|
return list(to_post)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def workflow_to_end(cls, sales):
|
||||||
|
pool = Pool()
|
||||||
|
StatementLine = pool.get('account.statement.line')
|
||||||
|
Invoice = pool.get('account.invoice')
|
||||||
|
|
||||||
for sale in sales:
|
for sale in sales:
|
||||||
if sale.state == 'draft':
|
if sale.state == 'draft':
|
||||||
cls.quote([sale])
|
cls.quote([sale])
|
||||||
@ -79,36 +98,27 @@ class Sale(metaclass=PoolMeta):
|
|||||||
'sale_payment.not_customer_invoice',
|
'sale_payment.not_customer_invoice',
|
||||||
reference=sale.reference))
|
reference=sale.reference))
|
||||||
|
|
||||||
grouping = getattr(sale.party, 'sale_invoice_grouping_method',
|
to_post = cls.set_invoices_to_be_posted(sales)
|
||||||
False)
|
|
||||||
if sale.invoices and not grouping:
|
|
||||||
for invoice in sale.invoices:
|
|
||||||
if not invoice.state == 'draft':
|
|
||||||
continue
|
|
||||||
sale.set_values_to_invoice(invoice)
|
|
||||||
invoices.extend(([invoice], invoice._save_values))
|
|
||||||
to_post.add(invoice)
|
|
||||||
|
|
||||||
if to_post:
|
if to_post:
|
||||||
Invoice.write(*invoices)
|
Invoice.post(to_post)
|
||||||
Invoice.post(list(to_post))
|
|
||||||
|
|
||||||
to_write = []
|
to_write = []
|
||||||
to_do = []
|
to_do = []
|
||||||
for sale in sales:
|
for sale in sales:
|
||||||
for payment in sale.payments:
|
posted_invoice = None
|
||||||
invoices = [invoice for invoice in sale.invoices
|
for invoice in sale.invoices:
|
||||||
if invoice and invoice.state == 'posted']
|
if invoice.state == 'posted':
|
||||||
if not invoices:
|
posted_invoice = invoice
|
||||||
continue
|
break
|
||||||
payment.invoice = invoices[0]
|
if posted_invoice:
|
||||||
# Because of account_invoice_party_without_vat module
|
for payment in sale.payments:
|
||||||
# could be installed, invoice party may be different of
|
# Because of account_invoice_party_without_vat module
|
||||||
# payment party if payment party has not any vat
|
# could be installed, invoice party may be different of
|
||||||
# and both parties must be the same
|
# payment party if payment party has not any vat
|
||||||
if payment.party != invoice.party:
|
# and both parties must be the same
|
||||||
payment.party = invoice.party
|
if payment.party != invoice.party:
|
||||||
to_write.extend(([payment], payment._save_values))
|
payment.party = invoice.party
|
||||||
|
to_write.extend(([payment], payment._save_values))
|
||||||
|
|
||||||
if sale.is_done():
|
if sale.is_done():
|
||||||
to_do.append(sale)
|
to_do.append(sale)
|
||||||
|
Loading…
Reference in New Issue
Block a user