[IMP] sale: Change the default invoicing method if there are downpayments

Purpose
=======

Currently the default invoicing method is not very clear.

Specification
=============

Currently the result is not really correct. We can propose to deduct
the down payment even if there are no down payments on the sales order.

Now the option to deduct down payments will be selected if there
is a downpayment line on the sales order and if there exists at
least one invoice linked to the sales order that is not cancelled.

Task ID : 33126
This commit is contained in:
Kirti Choudhary
2018-07-30 14:57:04 +02:00
committed by Yannick Tivisse
parent d24b7503cd
commit 3d46887d38
@@ -21,11 +21,11 @@ class SaleAdvancePaymentInv(models.TransientModel):
if self._count() == 1:
sale_obj = self.env['sale.order']
order = sale_obj.browse(self._context.get('active_ids'))[0]
if all([line.product_id.invoice_policy == 'order' for line in order.order_line]) or order.invoice_count:
if order.order_line.filtered(lambda dp: dp.is_downpayment) and order.invoice_ids.filtered(lambda invoice: invoice.state != 'cancel'):
return 'all'
else:
return 'all'
return 'delivered'
else:
return 'delivered'
return 'all'
@api.model
def _default_product_id(self):