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.

40 lines
1.7 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
# template.list_price_ref_pack = template.pack_line_ids[0].product_id.list_price
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