<commit_before># -*- coding: utf-8 -*-
# Copyright 2015-2017 Tecnativa - <NAME>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import math
from odoo import api, fields, models


class ComputeVatProrrate(models.TransientModel):
    _name = "l10n.es.aeat.compute.vat.prorrate"

    def _default_year(self):
        return int(fields.Date.today()[:4])

    year = fields.Integer(
        required=True,
        default=_default_year,
    )

    @api.multi
    def button_compute(self):
        self.ensure_one()
        date_from = '%s-01-01' % self.year
        date_to = '%s-12-31' % self.year
        mod303 = self.env['l10n.es.aeat.mod303.report'].browse(
            self.env.context['active_id']
        )
        # Get base amount for taxed operations
        taxed_taxes_codes = [
            'S_IVA4B', 'S_IVA4S',
            'S_IVA10B', 'S_IVA10S',
            'S_IVA21B', 'S_IVA21S', 'S_IVA21ISP',
        ]
        move_lines = mod303._get_tax_lines(
            taxed_taxes_codes, date_from, date_to, 'regular', 'base', 'both',
        )
        taxed = (sum(move_lines.mapped('credit')) -
                 sum(move_lines.mapped('debit')))
        move_lines = mod303._get_tax_lines(
            taxed_taxes_codes, date_from, date_to, 'refund', 'base', 'both',
        )
        taxed += (sum(move_lines.mapped('credit')) -
                  sum(move_lines.mapped('debit')))
        # Get base amount of exempt operations
        move_lines = mod303._get_tax_lines(
            ['S_IVA0'], date_from, date_to, 'all', 'base', 'both',
        )
        exempt = (sum(move_lines.mapped('credit')) -
                  sum(move_lines.mapped('debit')))
        # compute prorrate percentage performing ceiling operation
        mod303.vat_prorrate_percent = math.ceil(taxed / (taxed + exempt) * 100)
        return True
<commit_msg>[IMP] l10n_es_aeat: Add tax_exigibility option to tax mapping<commit_after># -*- coding: utf-8 -*-
# Copyright 2015-2017 Tecnativa - <NAME>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

import math
from odoo import api, fields, models


class ComputeVatProrrate(models.TransientModel):
    _name = "l10n.es.aeat.compute.vat.prorrate"

    def _default_year(self):
        return int(fields.Date.today()[:4])

    year = fields.Integer(
        required=True,
        default=_default_year,
    )

    @api.multi
    def button_compute(self):
        self.ensure_one()
        date_from = '%s-01-01' % self.year
        date_to = '%s-12-31' % self.year
        mod303 = self.env['l10n.es.aeat.mod303.report'].browse(
            self.env.context['active_id']
        )
        # Get base amount for taxed operations
        taxed_taxes_codes = [
            'S_IVA4B', 'S_IVA4S',
            'S_IVA10B', 'S_IVA10S',
            'S_IVA21B', 'S_IVA21S', 'S_IVA21ISP',
        ]
        MapLine = self.env['l10n.es.aeat.map.tax.line']
        map_line = MapLine.new({
            'move_type': 'all',
            'field_type': 'base',
            'sum_type': 'both',
            'exigible_type': 'yes',
        })
        move_lines = mod303._get_tax_lines(
            taxed_taxes_codes, date_from, date_to, map_line,
        )
        taxed = (sum(move_lines.mapped('credit')) -
                 sum(move_lines.mapped('debit')))
        # Get base amount of exempt operations
        move_lines = mod303._get_tax_lines(
            ['S_IVA0'], date_from, date_to, map_line,
        )
        exempt = (sum(move_lines.mapped('credit')) -
                  sum(move_lines.mapped('debit')))
        # compute prorrate percentage performing ceiling operation
        mod303.vat_prorrate_percent = math.ceil(taxed / (taxed + exempt) * 100)
        return True

{'fraction_non_alphanumeric': 0.1328145961899651, 'fraction_numerical': 0.031929165548698686, 'mean_word_length': 2.233304423243712, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6961877', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1275, 'n_words': 224}