[FIX] account,sale: is_downpayment method on account_move

Currently there is no simple way of finding if an invoice is a
downpayment.

Downpayments can be created from a sale order. An invoice is generated
representing the downpayment. When the sale order is used to generate
the complete invoice, the downpayment is deducted.

There is no fast way to distinguish a downpayment invoice. The only way
of knowing is that the lines of the invoice will have sale_line_ids for
which 'is_downpayment' (a boolean field on the sale order line) is true.
(also, by default, the product 'Downpayment' is used for the invoice
line representing the downpayment)

This commit adds a helper method '_is_downpayment' to the account.move
model, which will return False if sale is not installed, and True if
sale is installed, and is_downpayment (the boolean field on
sale.order.line) is true of all the sale lines associated with all the
lines of the invoice.

Another method '_get_downpayment_lines' is added to the
account.move.line model which, for all sale lines associated with the
move line upon which it is called, returns the invoice lines of the sale
lines for which their move_id._is_downpayment() is true. This
distinguishes between the downpayment lines in the final invoice (which
aren't retrieved by this method), and the downpayment lines in the
downpayment invoice (which are retrieved by this method).

Part-of: odoo/odoo#98534
This commit is contained in:
dbkosky
2022-08-22 16:48:50 +02:00
committed by dbkosky
parent c0bbe22642
commit b23c485f16
4 changed files with 21 additions and 0 deletions
+6
View File
@@ -3633,3 +3633,9 @@ class AccountMove(models.Model):
:returns: A list of tuples (priority, method) where method takes an attachment as parameter.
"""
return []
def _is_downpayment(self):
''' Return true if the invoice is a downpayment.
Down-payments can be created from a sale order. This method is overridden in the sale order module.
'''
return False
@@ -2589,3 +2589,9 @@ class AccountMoveLine(models.Model):
def _copy_data_extend_business_fields(self, values):
self.ensure_one()
def _get_downpayment_lines(self):
''' Return the downpayment move lines associated with the move line.
This method is overridden in the sale order module.
'''
return self.env['account.move.line']
+5
View File
@@ -125,3 +125,8 @@ class AccountMove(models.Model):
else:
result = {'type': 'ir.actions.act_window_close'}
return result
def _is_downpayment(self):
# OVERRIDE
self.ensure_one()
return self.line_ids.sale_line_ids and all(sale_line.is_downpayment for sale_line in self.line_ids.sale_line_ids) or False
+4
View File
@@ -203,3 +203,7 @@ class AccountMoveLine(models.Model):
if currency_id and currency_id != order.currency_id:
price_unit = currency_id._convert(price_unit, order.currency_id, order.company_id, order.date_order or fields.Date.today())
return price_unit
def _get_downpayment_lines(self):
# OVERRIDE
return self.sale_line_ids.filtered('is_downpayment').invoice_lines.filtered(lambda line: line.move_id._is_downpayment())