<commit_before># Copyright 2020 KMEE INFORMATICA LTDA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from lxml import etree

from odoo import api, fields, models


class DocumentLine(models.Model):
    _inherit = 'l10n_br_fiscal.document.line'

    fiscal_deductions_value = fields.Monetary(
        string='Fiscal Deductions',
        default=0.00,
    )
    other_retentions_value = fields.Monetary(
        string='Other Retentions',
        default=0.00,
    )
    city_taxation_code_id = fields.Many2one(
        string='City Taxation Code',
        comodel_name='l10n_br_fiscal.city.taxation.code'
    )

    cnae_id = fields.Many2one(
        comodel='l10n_br_fiscal.cnae',
        string='CNAE Code',
        related='product_id.cnae_id',
        store=True,
    )

    @api.onchange("product_id")
    def _onchange_product_id_fiscal(self):
        super(DocumentLine, self)._onchange_product_id_fiscal()
        if self.product_id and self.product_id.fiscal_deductions_value:
            self.fiscal_deductions_value = \
                self.product_id.fiscal_deductions_value
        if self.product_id and self.product_id.city_taxation_code_id:
            company_city_id = self.document_id.company_id.city_id
            city_id = self.product_id.city_taxation_code_id.filtered(
                lambda r: r.city_id == company_city_id)
            if city_id:
                self.city_taxation_code_id = city_id

    def _compute_taxes(self, taxes, cst=None):
        discount_value = self.discount_value
        self.discount_value += self.fiscal_deductions_value
        res = super(DocumentLine, self)._compute_taxes(taxes, cst)
        self.discount_value = discount_value
        return res

    @api.model
    def fields_view_get(self, view_id=None, view_type="form",
                        toolbar=False, submenu=False):
        model_view = super(DocumentLine, self).fields_view_get(
            view_id, view_type, toolbar, submenu)

        if view_type == 'form':
            try:
                doc = etree.fromstring(model_view.get('arch'))
                field = doc.xpath("//field[@name='issqn_<EMAIL>']")[0]
                parent = field.getparent()
                parent.insert(parent.index(field)+1, etree.XML(
                    '<field name="other_retentions_value"/>'
                ))

                model_view["arch"] = etree.tostring(doc, encoding='unicode')<commit_msg>[IMP] Onchange Cnae Code on Document Line<commit_after># Copyright 2020 KMEE INFORMATICA LTDA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from lxml import etree

from odoo import api, fields, models


class DocumentLine(models.Model):
    _inherit = 'l10n_br_fiscal.document.line'

    fiscal_deductions_value = fields.Monetary(
        string='Fiscal Deductions',
        default=0.00,
    )
    other_retentions_value = fields.Monetary(
        string='Other Retentions',
        default=0.00,
    )
    city_taxation_code_id = fields.Many2one(
        string='City Taxation Code',
        comodel_name='l10n_br_fiscal.city.taxation.code'
    )

    cnae_id = fields.Many2one(
        comodel='l10n_br_fiscal.cnae',
        string='CNAE Code',
        related='product_id.cnae_id',
        store=True,
    )

    @api.onchange("product_id")
    def _onchange_product_id_fiscal(self):
        super(DocumentLine, self)._onchange_product_id_fiscal()
        if self.product_id and self.product_id.fiscal_deductions_value:
            self.fiscal_deductions_value = \
                self.product_id.fiscal_deductions_value
        if self.product_id and self.product_id.city_taxation_code_id:
            company_city_id = self.document_id.company_id.city_id
            city_id = self.product_id.city_taxation_code_id.filtered(
                lambda r: r.city_id == company_city_id)
            if city_id:
                self.city_taxation_code_id = city_id
        if self.product_id and self.product_id.cnae_id:
            self.cnae_id = self.product_id.cnae_id

    def _compute_taxes(self, taxes, cst=None):
        discount_value = self.discount_value
        self.discount_value += self.fiscal_deductions_value
        res = super(DocumentLine, self)._compute_taxes(taxes, cst)
        self.discount_value = discount_value
        return res

    @api.model
    def fields_view_get(self, view_id=None, view_type="form",
                        toolbar=False, submenu=False):
        model_view = super(DocumentLine, self).fields_view_get(
            view_id, view_type, toolbar, submenu)

        if view_type == 'form':
            try:
                doc = etree.fromstring(model_view.get('arch'))
                field = doc.xpath("//field[@name='issqn_wh_value']")[0]
                parent = field.getparent()
                parent.insert(parent.index(field)+1, etree.XML(
                    '<field name="other_retentions_value"/>'
                ))

                model_view["arch"] = etree.tostring(doc, encoding='unicode')
{'fraction_non_alphanumeric': 0.09916033586565375, 'fraction_numerical': 0.008796481407437025, 'mean_word_length': 2.4986013986013984, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '6702292', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1623, 'n_words': 255}