[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:
@@ -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']
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user