[FIX] account, point_of_sale: correct tax_audit computation for pos returns

https://github.com/odoo/enterprise/pull/12091 changed the way the tax report computes its totals wit account moves resulting for return operations in pos. This commit does the same on tax_audit field, so that it stays consistent with the report.

closes odoo/odoo#55664

X-original-commit: 67b3d70c8425dee17731e7b94bcb4797d4b06a97
Related: odoo/enterprise#12320
Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
oco-odoo
2020-08-10 08:14:23 +00:00
parent 2be6e37aca
commit be63b44845
2 changed files with 20 additions and 1 deletions
+8 -1
View File
@@ -3473,7 +3473,7 @@ class AccountMoveLine(models.Model):
# Cash basis entries are always treated as misc operations, applying the tag sign directly to the balance
type_multiplicator = 1
else:
type_multiplicator = (record.journal_id.type == 'sale' and -1 or 1) * (record.move_id.move_type in ('in_refund', 'out_refund') and -1 or 1)
type_multiplicator = (record.journal_id.type == 'sale' and -1 or 1) * (self._get_refund_tax_audit_condition(record) and -1 or 1)
tag_amount = type_multiplicator * (tag.tax_negate and -1 or 1) * record.balance
@@ -3489,6 +3489,13 @@ class AccountMoveLine(models.Model):
record.tax_audit = audit_str
def _get_refund_tax_audit_condition(self, aml):
""" Returns the condition to be used for the provided move line to tell
whether or not it comes from a refund operation.
This is overridden by pos in order to treat returns properly.
"""
return aml.move_id.move_type in ('in_refund', 'out_refund') and -1 or 1
# -------------------------------------------------------------------------
# CONSTRAINT METHODS
# -------------------------------------------------------------------------
@@ -35,3 +35,15 @@ class AccountMoveLine(models.Model):
if order:
price_unit = order._get_pos_anglo_saxon_price_unit(self.product_id, self.move_id.partner_id.id, self.quantity)
return price_unit
def _get_refund_tax_audit_condition(self, aml):
# Overridden so that the returns can be detected as credit notes by the tax audit computation
rslt = super()._get_refund_tax_audit_condition(aml)
if aml.move_id.is_invoice():
# We don't need to check the pos orders for this move line if an invoice
# is linked to it ; we know that the invoice type tells us whether it's a refund
return rslt
pos_orders_count = self.env['pos.order'].search_count([('account_move', '=', aml.move_id.id)])
return rslt or (pos_orders_count and aml.debit > 0)