(self, tax_lines)
return all_lines
Añadir la parte no deducida de la base como gasto repartido
        proporcionalmente entre las cuentas de las líneas de gasto existentes.
Añadir la parte no deducida de la base como gasto repartido
        proporcionalmente entre las cuentas de las líneas de gasto existentes.
Añadir la parte no deducida de la base como gasto repartido proporcionalmente entre las cuentas de las líneas de gasto existentes .
def _process_tax_line_regularization(self, tax_lines):
        """Añadir la parte no deducida de la base como gasto repartido
        proporcionalmente entre las cuentas de las líneas de gasto existentes.
        """
        all_lines = []
        move_line_obj = self.env["account.move.line"]
        for tax_line in tax_lines:
            # We need to treat each tax_line independently
            lines = super()._process_tax_line_regularization(tax_line)
            all_lines += lines
            if (
                self.vat_prorrate_type != "general"
                or tax_line.field_number not in PRORRATE_TAX_LINE_MAPPING.keys()
            ):
                continue
            factor = (100 - self.vat_prorrate_percent) / 100
            base_tax_line = self.tax_line_ids.filtered(
                lambda x: (
                    x.field_number == PRORRATE_TAX_LINE_MAPPING[tax_line.field_number]
                )
            )
            if not base_tax_line.move_line_ids:
                continue
            tax_account_groups = move_line_obj.read_group(
                [("id", "in", tax_line.move_line_ids.ids)],
                ["debit", "credit", "tax_line_id"],
                ["tax_line_id"],
            )
            total_prorrate = 0
            extra_lines = []
            # Split by tax for having the proportional part
            for tax_account_group in tax_account_groups:
                prorrate_debit = tax_account_group["debit"]
                prorrate_credit = tax_account_group["credit"]
                prec = self.env["decimal.precision"].precision_get("Account")
                subtotal_prorrate = round(
                    (prorrate_debit - prorrate_credit) * factor, prec
                )
                total_prorrate += subtotal_prorrate
                account_groups = move_line_obj.read_group(
                    [
                        ("id", "in", base_tax_line.move_line_ids.ids),
                        ("tax_ids", "=", tax_account_group["tax_line_id"][0]),
                    ],
                    ["balance", "account_id", "analytic_account_id"],
                    ["account_id", "analytic_account_id"],
                )
                total_balance = sum(x["balance"] for x in account_groups)
                amount_factor = abs(subtotal_prorrate) / abs(total_balance)
                for account_group in account_groups:
                    analytic_groups = move_line_obj.read_group(
                        account_group["__domain"],
                        ["balance", "analytic_account_id"],
                        ["analytic_account_id"],
                    )
                    for analytic_group in analytic_groups:
                        balance = analytic_group["balance"] * amount_factor
                        move_line_vals = {
                            "name": account_group["account_id"][1],
                            "account_id": account_group["account_id"][0],
                            "debit": (round(balance, prec) if balance > 0 else 0),
                            "credit": (round(-balance, prec) if balance < 0 else 0),
                        }
                        if analytic_group["analytic_account_id"]:
                            move_line_vals["analytic_account_id"] = (
                                analytic_group["analytic_account_id"]
                            )[0]
                        extra_lines.append(move_line_vals)
            # Add/substract possible rounding inaccuracy to the first line
            extra_lines = self._prorrate_diff_distribution(total_prorrate, extra_lines)
            all_lines += extra_lines
        return all_lines
def _process_tax_line_regularization ( self , tax_lines ) : all_lines = [ ] move_line_obj = self . env [ "account.move.line" ] for tax_line in tax_lines : # We need to treat each tax_line independently lines = super ( ) . _process_tax_line_regularization ( tax_line ) all_lines += lines if ( self . vat_prorrate_type != "general" or tax_line . field_number not in PRORRATE_TAX_LINE_MAPPING . keys ( ) ) : continue factor = ( 100 - self . vat_prorrate_percent ) / 100 base_tax_line = self . tax_line_ids . filtered ( lambda x : ( x . field_number == PRORRATE_TAX_LINE_MAPPING [ tax_line . field_number ] ) ) if not base_tax_line . move_line_ids : continue tax_account_groups = move_line_obj . read_group ( [ ( "id" , "in" , tax_line . move_line_ids . ids ) ] , [ "debit" , "credit" , "tax_line_id" ] , [ "tax_line_id" ] , ) total_prorrate = 0 extra_lines = [ ] # Split by tax for having the proportional part for tax_account_group in tax_account_groups : prorrate_debit = tax_account_group [ "debit" ] prorrate_credit = tax_account_group [ "credit" ] prec = self . env [ "decimal.precision" ] . precision_get ( "Account" ) subtotal_prorrate = round ( ( prorrate_debit - prorrate_credit ) * factor , prec ) total_prorrate += subtotal_prorrate account_groups = move_line_obj . read_group ( [ ( "id" , "in" , base_tax_line . move_line_ids . ids ) , ( "tax_ids" , "=" , tax_account_group [ "tax_line_id" ] [ 0 ] ) , ] , [ "balance" , "account_id" , "analytic_account_id" ] , [ "account_id" , "analytic_account_id" ] , ) total_balance = sum ( x [ "balance" ] for x in account_groups ) amount_factor = abs ( subtotal_prorrate ) / abs ( total_balance ) for account_group in account_groups : analytic_groups = move_line_obj . read_group ( account_group [ "__domain" ] , [ "balance" , "analytic_account_id" ] , [ "analytic_account_id" ] , ) for analytic_group in analytic_groups : balance = analytic_group [ "balance" ] * amount_factor move_line_vals = { "name" : account_group [ "account_id" ] [ 1 ] , "account_id" : account_group [ "account_id" ] [ 0 ] , "debit" : ( round ( balance , prec ) if balance > 0 else 0 ) , "credit" : ( round ( - balance , prec ) if balance < 0 else 0 ) , } if analytic_group [ "analytic_account_id" ] : move_line_vals [ "analytic_account_id" ] = ( analytic_group [ "analytic_account_id" ] ) [ 0 ] extra_lines . append ( move_line_vals ) # Add/substract possible rounding inaccuracy to the first line extra_lines = self . _prorrate_diff_distribution ( total_prorrate , extra_lines ) all_lines += extra_lines return all_lines