<commit_before># -*- coding: utf-8 -*-
# © 2016 Comunitea Servicios Tecnológicos (<http://www.comunitea.com>)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, fields, api


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'

    @api.model
    def _default_agents(self):
        """
        Check if there is a delivery address in the sale order and adds the
        agent and commission for this address if exists.
        """
        res = super(SaleOrderLine, self)._default_agents()
        t_partner = self.env['res.partner']
        res_extended = []
        partner = False
        if not self.env.context.get('partner_id'):
            return res
        partner = t_partner.browse(self.env.context['partner_id'])
        ship_address_id = self.env.context.get('address_id', False)
        if ship_address_id and ship_address_id != partner.id:
            sol = self.with_context(partner_id=self._context['address_id'])
            res_extended = super(SaleOrderLine, sol)._default_agents()

        res.extend(res_extended)
        return res

    agents = fields.One2many(default=_default_agents)


class SaleOrderLineAgent(models.Model):

    _inherit = 'sale.order.line.agent'

    _sql_constraints = [
        ('unique_agent', 'Check(1=1)',
         'You can only add one time each agent.!'),
    ]<commit_msg>[FIX]eln_sale_commission: Cuando la dirección de entrega tiene comisiones no se añaden las del partner.<commit_after># -*- coding: utf-8 -*-
# © 2016 Comunitea Servicios Tecnológicos (<http://www.comunitea.com>)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, fields, api


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'

    @api.model
    def _default_agents(self):
        """
        Check if there is a delivery address in the sale order and adds the
        agent and commission for this address if exists.
        """
        t_partner = self.env['res.partner']
        res_extended = []
        partner = False
        if not self.env.context.get('partner_id'):
            return res
        partner = t_partner.browse(self.env.context['partner_id'])
        ship_address_id = self.env.context.get('address_id', False)
        if ship_address_id and ship_address_id != partner.id:
            sol = self.with_context(partner_id=self._context['address_id'])
            return super(SaleOrderLine, sol)._default_agents()
        return super(SaleOrderLine, self)._default_agents()

    agents = fields.One2many(default=_default_agents)


class SaleOrderLineAgent(models.Model):

    _inherit = 'sale.order.line.agent'

    _sql_constraints = [
        ('unique_agent', 'Check(1=1)',
         'You can only add one time each agent.!'),
    ]
{'fraction_non_alphanumeric': 0.11527480371163455, 'fraction_numerical': 0.007851534618129907, 'mean_word_length': 2.829234972677596, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '6425875', 'n_tokens_mistral': 905, 'n_tokens_neox': 864, 'n_words': 202}