diff --git a/product_pack/__manifest__.py b/product_pack/__manifest__.py index f94b1a2a7..8a72d4796 100644 --- a/product_pack/__manifest__.py +++ b/product_pack/__manifest__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name': 'Product Pack', - 'version': '11.0.1.3.0', + 'version': '11.0.1.4.0', 'category': 'Product', 'sequence': 14, 'summary': '', diff --git a/product_pack/models/product_pack_line.py b/product_pack/models/product_pack_line.py index 1a2cb8f99..b1d66b901 100644 --- a/product_pack/models/product_pack_line.py +++ b/product_pack/models/product_pack_line.py @@ -37,60 +37,29 @@ class ProductPack(models.Model): @api.multi def get_sale_order_line_vals(self, line, order): self.ensure_one() - # pack_price = 0.0 - subproduct = self.product_id quantity = self.quantity * line.product_uom_qty - - taxes = order.fiscal_position_id.map_tax( - subproduct.taxes_id.filtered( - lambda r: r.company_id.id == order.company_id.id)) - tax_id = [(6, 0, taxes.ids)] - - # if pack is fixed price or totlice price we don want amount on - # pack lines - if line.product_id.pack_price_type in [ - 'fixed_price', 'totalice_price']: - price = 0.0 - discount = 0.0 - else: - pricelist = order.pricelist_id.id - price = self.env['product.pricelist'].with_context( - context={ - 'uom': subproduct.uom_id.id, - 'date': order.date_order, - } - ).price_get( - subproduct.id, quantity, - order.partner_id.id)[pricelist] - discount = self.discount - - # Obtain product name in partner's language - if order.partner_id.lang: - subproduct = subproduct.with_context( - lang=order.partner_id.lang) - subproduct_name = subproduct.name - - vals = { + line_vals = { 'order_id': order.id, - 'name': '%s%s' % ( - '> ' * (line.pack_depth + 1), subproduct_name - ), - # 'delay': subproduct.sale_delay or 0.0, - 'product_id': subproduct.id, - # 'procurement_ids': ( - # [(4, x.id) for x in line.procurement_ids] - # ), - 'price_unit': price, - 'tax_id': tax_id, - 'address_allotment_id': False, - 'product_uom_qty': quantity, - 'product_uom': subproduct.uom_id.id, - 'product_packaging': False, - 'discount': discount, - 'number_packages': False, - 'th_weight': False, - 'state': 'draft', + 'product_id': self.product_id.id or False, 'pack_parent_line_id': line.id, 'pack_depth': line.pack_depth + 1, + # 'sequence': sequence, + 'company_id': order.company_id.id, } + sol = line.new(line_vals) + sol.product_id_change() + sol.product_uom_qty = quantity + sol.product_uom_change() + sol._onchange_discount() + vals = sol._convert_to_write(sol._cache) + + discount = 100.0 - ( + (100.0 - sol.discount) * (100.0 - self.discount) / 100.0) + + vals.update({ + 'discount': discount, + 'name': '%s%s' % ( + '> ' * (line.pack_depth + 1), sol.name + ), + }) return vals diff --git a/product_pack/models/product_product.py b/product_pack/models/product_product.py index 1040750d3..c0d3873ba 100644 --- a/product_pack/models/product_product.py +++ b/product_pack/models/product_product.py @@ -93,7 +93,7 @@ def price_compute(self, price_type, uom=False, currency=False, packs, no_packs = self.separete_pack_products() prices = super(ProductProduct, no_packs).price_compute( price_type, uom, currency, company) - for product in packs: + for product in packs.with_context(prefetch_fields=False): pack_price = 0.0 for pack_line in product.pack_line_ids: product_line_price = pack_line.product_id.price * ( diff --git a/product_pack/models/product_template.py b/product_pack/models/product_template.py index 0a56dbd1e..a79425575 100644 --- a/product_pack/models/product_template.py +++ b/product_pack/models/product_template.py @@ -39,8 +39,10 @@ class ProductTemplate(models.Model): related='product_variant_ids.used_pack_line_ids', readonly=True, ) - allow_modify_pack = fields.Boolean( - ) + allow_modify_pack = fields.Selection([ + ('only_backend', 'Only backend'), + ('frontend_backend', 'E-commerce and Bankend'), + ]) @api.onchange('pack_price_type') def onchange_allow_modify_pack(self): diff --git a/product_pack/models/sale_order.py b/product_pack/models/sale_order.py index 74fb303c5..d08976099 100644 --- a/product_pack/models/sale_order.py +++ b/product_pack/models/sale_order.py @@ -24,7 +24,10 @@ def check_pack_line_unlink(self): _origin.order_line only when lines are unlinked and this is exactly what we need """ - if self._origin.order_line.filtered('pack_parent_line_id'): + if self._origin.order_line.filtered( + lambda x: x.pack_parent_line_id and + x.pack_parent_line_id.product_id.allow_modify_pack not in [ + 'only_backend', 'frontend_backend']): raise UserError(_( 'You can not delete this line because is part of a pack in' ' this sale order. In order to delete this line you need to' diff --git a/product_pack/models/sale_order_line.py b/product_pack/models/sale_order_line.py index a76a7d95d..63b4c794a 100644 --- a/product_pack/models/sale_order_line.py +++ b/product_pack/models/sale_order_line.py @@ -43,6 +43,8 @@ class SaleOrderLine(models.Model): @api.constrains('product_id', 'price_unit', 'product_uom_qty') def expand_pack_line(self): + if self._context.get('update_pricelist', False): + return detailed_packs = ['components_price', 'totalice_price', 'fixed_price'] if ( self.state == 'draft' and @@ -102,6 +104,8 @@ def _onchange_pack_line_ids(self): @api.constrains('product_id') def expand_none_detailed_pack(self): + if self._context.get('update_pricelist', False): + return if self.product_id.pack_price_type == 'none_detailed_assited_price': # remove previus existing lines self.pack_line_ids.unlink() @@ -137,7 +141,8 @@ def check_pack_line_modify(self): """ Do not let to edit a sale order line if this one belongs to pack """ if self._origin.pack_parent_line_id and \ - not self._origin.pack_parent_line_id.product_id.allow_modify_pack: + self._origin.pack_parent_line_id.product_id.allow_modify_pack \ + not in ['only_backend', 'frontend_backend']: raise UserError(_( 'You can not change this line because is part of a pack' ' included in this order')) diff --git a/product_pack/views/product_product_views.xml b/product_pack/views/product_product_views.xml index 3582a1eb1..87156546e 100644 --- a/product_pack/views/product_product_views.xml +++ b/product_pack/views/product_product_views.xml @@ -8,6 +8,7 @@ +