<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014 Pexego Sistemas Informáticos All Rights Reserved
#    $<NAME> <<EMAIL>>$
#    Copyright (C) 2016 Comunitea Servicios Tecnológicos
#    $<NAME> <<EMAIL>>$
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published
#    by the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp import models, fields, api


class sale_order_line(models.Model):

    _inherit = "sale.order.line"

    @api.one
    @api.depends("product_uom_qty", "price_unit", "discount", "product_id")
    def _product_margin(self):
        self.margin = 0.0
        self.margin_perc = 0.0
        self.purchase_price = 0.0

        if self.product_id and self.product_id.standard_price and \
                not self.pack_depth:
            self.purchase_price = self.product_id.standard_price
            sale_price = self.price_unit * self.product_uom_qty * \
                ((100.0 - self.discount) / 100.0)
            purchase_price = self.purchase_price * self.product_uom_qty
            margin = round(sale_price - purchase_price, 2)
            if sale_price:
                if sale_price < purchase_price:
                    self.margin_perc = round((margin * 100) / purchase_price, 2)
                else:
                    self.margin_perc = round((margin * 100) / sale_price, 2)
            elif sale_price == 0.0 and self.discount == 100:
                self.margin_perc = -100
            self.margin = margin

    @api.one
    @api.depends("product_uom_qty", "price_unit", "discount", "product_id")
    def _product_margin_rappel(self):
        self.margin_perc_rappel = 0.0
        self.purchase_price = 0.0

        if self.product_id and self.product_id.standard_price and not self.pack_depth:

            self.purchase_price = self.product_id.standard_price

            sale_price = self.price_unit * self.product_uom_qty * ((100.0 - self.discount) / 100.0)
            purchase_price = self.purchase_price * self.product_uom_qty
            if self.product_id.product_brand_id.name in self.env['rappel'].search([('name', 'like', 'Vale Ahorro%')],limit=1).mapped('brand_ids.name'):
                if self.order_id.partner_id.property_product_pricelist.name in ('PVPA 55', 'PVPB 55', 'PVPC 55'):
                    rappel = sale_price * 0.10
                elif self.order_id.partner_id.property_product_pricelist.name in ('PVPA 52,5', 'PVPB 52,5', 'PVPC 52,5'):
                    rappel = sale_price * 0.05
                else:
                    rappel = 0.0
            else:
                rappel = 0.0
            sale_price_rappel = sale_price - rappel
            margin = round(sale_price_rappel - purchase_price, 2)

            if sale_price:
                if sale_price < purchase_price:
                    self.margin_perc_rappel = round((margin * 100) / purchase_price, 2)
                else:
                    self.margin_perc_rappel = round((margin * 100) / sale_price_rappel, 2)
            elif sale_price == 0.0 and self.discount == 100:
                self.margin_perc_rappel = -100
            self.margin_rappel = margin

    margin = fields.Float(compute="_product_margin", string='Margin',
                          store=True, multi='marg', readonly=True)<commit_msg>[FIX]'sale_margin_percentage': Mejorada la comparación de marcas<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014 Pexego Sistemas Informáticos All Rights Reserved
#    $<NAME> <<EMAIL>>$
#    Copyright (C) 2016 Comunitea Servicios Tecnológicos
#    $<NAME> <<EMAIL>>$
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published
#    by the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp import models, fields, api


class sale_order_line(models.Model):

    _inherit = "sale.order.line"

    @api.one
    @api.depends("product_uom_qty", "price_unit", "discount", "product_id")
    def _product_margin(self):
        self.margin = 0.0
        self.margin_perc = 0.0
        self.purchase_price = 0.0

        if self.product_id and self.product_id.standard_price and \
                not self.pack_depth:
            self.purchase_price = self.product_id.standard_price
            sale_price = self.price_unit * self.product_uom_qty * \
                ((100.0 - self.discount) / 100.0)
            purchase_price = self.purchase_price * self.product_uom_qty
            margin = round(sale_price - purchase_price, 2)
            if sale_price:
                if sale_price < purchase_price:
                    self.margin_perc = round((margin * 100) / purchase_price, 2)
                else:
                    self.margin_perc = round((margin * 100) / sale_price, 2)
            elif sale_price == 0.0 and self.discount == 100:
                self.margin_perc = -100
            self.margin = margin

    @api.one
    @api.depends("product_uom_qty", "price_unit", "discount", "product_id")
    def _product_margin_rappel(self):
        self.margin_perc_rappel = 0.0
        self.purchase_price = 0.0

        if self.product_id and self.product_id.standard_price and not self.pack_depth:

            self.purchase_price = self.product_id.standard_price

            sale_price = self.price_unit * self.product_uom_qty * ((100.0 - self.discount) / 100.0)
            purchase_price = self.purchase_price * self.product_uom_qty
            if self.product_id.product_brand_id.id in self.env['rappel'].search([('name', 'like', 'Vale Ahorro%')], limit=1).brand_ids.ids:
                if self.order_id.partner_id.property_product_pricelist.name in ('PVPA 55', 'PVPB 55', 'PVPC 55'):
                    rappel = sale_price * 0.10
                elif self.order_id.partner_id.property_product_pricelist.name in ('PVPA 52,5', 'PVPB 52,5', 'PVPC 52,5'):
                    rappel = sale_price * 0.05
                else:
                    rappel = 0.0
            else:
                rappel = 0.0
            sale_price_rappel = sale_price - rappel
            margin = round(sale_price_rappel - purchase_price, 2)

            if sale_price:
                if sale_price < purchase_price:
                    self.margin_perc_rappel = round((margin * 100) / purchase_price, 2)
                else:
                    self.margin_perc_rappel = round((margin * 100) / sale_price_rappel, 2)
            elif sale_price == 0.0 and self.discount == 100:
                self.margin_perc_rappel = -100
            self.margin_rappel = margin

    margin = fields.Float(compute="_product_margin", string='Margin',
                          store=True, multi='marg', readonly=True)
{'fraction_non_alphanumeric': 0.13160183919473095, 'fraction_numerical': 0.02385982353672176, 'mean_word_length': 2.354731137974156, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 17, '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': '4143923', 'n_tokens_mistral': 2586, 'n_tokens_neox': 2353, 'n_words': 605}