You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
3.0 KiB

# © 2020 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.addons import decimal_precision as dp
class ProductTemplate(models.Model):
_inherit = 'product.template'
list_price_ref_pack = fields.Float(
'Prix référent au kilo', default=1.0,
digits=dp.get_precision('Product Price'),
compute='_compute_list_price_ref_pack')
price_ref_pack_compute = fields.Float(
'Prix calculé', default=1.0,
digits=dp.get_precision('Product Price'),
compute='_compute_price_ref_pack_compute')
def _compute_list_price_ref_pack(self):
for template in self:
if template.pack_line_ids:
if template.pack_ok and (template.pack_type == 'detailed' and template.pack_component_price == 'totalized'):
pack_price_ref = 0.0
for pack_line in template.pack_line_ids:
pack_price_ref += pack_line.product_id.list_price
template.list_price_ref_pack = pack_price_ref
def _compute_price_ref_pack_compute(self):
for template in self:
if template.pack_line_ids:
if template.pack_ok and (template.pack_type == 'detailed' and template.pack_component_price == 'totalized'):
pack_price = 0.0
for pack_line in template.pack_line_ids:
pack_price += pack_line.product_id.list_price * pack_line.quantity
template.price_ref_pack_compute = pack_price
@api.multi
def website_publish_button(self):
self.ensure_one()
res = super(ProductTemplate, self).website_publish_button()
# Dépublie les packs enfants si il en existe
if self.used_in_pack_line_ids:
for pack in self.used_in_pack_line_ids:
pack.parent_product_id.write({'website_published': not self.website_published})
return res
@api.multi
def get_info_parent_pack(self):
for pack in self:
if pack.pack_line_ids:
if pack.pack_ok and (
pack.pack_type == 'detailed' and pack.pack_component_price == 'totalized'):
product_parent_id = pack.pack_line_ids[0].product_id
pack.description_sale = product_parent_id.description_sale
if product_parent_id.image:
pack.write({
'image': product_parent_id.image,
'image_small': product_parent_id.image_small,
'image_medium': product_parent_id.image_medium,
})
if product_parent_id.product_image_ids:
pack.write({
'product_image_ids': [(6, 0, product_parent_id.product_image_ids.ids)]
})