<commit_before># -*- coding: utf-8 -*-
# © 2016 Comunitea
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api, _
from openerp.exceptions import except_orm


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'

    @api.multi
    def write(self, vals):
        for line in self:
            if vals.get('product_id', False):
                product = self.env['product.product'].browse(vals['product_id'])
                vals['name'] = product.name_get()[0][1]
                if product.description_sale:
                    vals['name'] += '\n' + product.description_sale
        return super(SaleOrderLine, self).write(vals)

    @api.multi<commit_msg>[FIX] 'sale_custom': Se ha modificado el metodo write de sale.order.line para que cuando se modifique la cantidad de un pack, se modifiquen tambien las cantidades de los productos que conformen el pack sin tener que hacerlo a mano. Al modificar el pack y guardar, se recalcula las cantidades de los productos que forman el pack y se hace un write sobre ellos, teniendo en cuenta el pack sobre el que se aplican esos productos.<commit_after># -*- coding: utf-8 -*-
# © 2016 Comunitea
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api, _
from openerp.exceptions import except_orm


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'

    @api.multi
    def write(self, vals):
        data = {}
        for line in self:
            if vals.get('product_uom_qty', False) and line.product_id.pack_line_ids:
                for subline in line.product_id.pack_line_ids:
                    subproduct = subline.product_id
                    quantity = subline.quantity * vals['product_uom_qty']
                    subproduct_id = self.env['sale.order.line'].search([('product_id', '=', subproduct.id),
                                                                        ('order_id', '=', line.order_id.id),
                                                                        ('pack_parent_line_id', '=', line.id)])
                    data = {'product_uom_qty': quantity}
                    subproduct_id.write(data)
            if vals.get('product_id', False):
                product = self.env['product.product'].browse(vals['product_id'])
                vals['name'] = product.name_get()[0][1]
                if product.description_sale:
                    vals['name'] += '\n' + product.description_sale
        return super(SaleOrderLine, self).write(vals)

    @api.multi
{'fraction_non_alphanumeric': 0.1132295719844358, 'fraction_numerical': 0.007003891050583658, 'mean_word_length': 2.143031784841076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '356904', 'n_tokens_mistral': 777, 'n_tokens_neox': 724, 'n_words': 194}