diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 495006bc812..4c60fdeb948 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -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 # ------------------------------------------------------------------------- diff --git a/addons/point_of_sale/models/account_move.py b/addons/point_of_sale/models/account_move.py index 0874ab2ea7f..c23902ec113 100644 --- a/addons/point_of_sale/models/account_move.py +++ b/addons/point_of_sale/models/account_move.py @@ -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)