Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1100 Vistas

Hello,


We sell Batteries and other electrical products, in Belgium, it is mandatory to pay contributions to the government for recycling of the products.

this is called BEBAT - for batteries and RECUPEL - for electronics


i want to add those contributions directly to the product, so when i make a quotation of a home battery, a second line with the contribution automatically appears. this should happen on the ecommerce as well. is it possible to add those extra prices to products?

(i can not add the contribution to the base price, as the VAT wil be wrong on the invoice, and the government demands that it has to be a separate line on the invoice)

For example when i add battery "Lithium-LFP Phosphate battery 48V 3552Wh / 3374Wh" it should automatically add the line "BEBAT CONTRIBUTION" and calculate the VAT separatly on the two prices



Thanks in advance!

Avatar
Descartar
Mejor respuesta

Hi,

Please refer to the code:



from odoo import models, api


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'


    @api.model_create_multi

    def create(self, vals_list):

        """Automatically add contribution line when a battery/electronic product is added"""

        lines = super().create(vals_list)

        for line in lines:

            product = line.product_id

            order = line.order_id


            # Only add contribution for specific categories

            if product.categ_id and product.categ_id.name in ['Batteries', 'Electronics']:

                # Determine contribution product

                if product.categ_id.name == 'Batteries':

                    contribution_product = self.env.ref('bebat_contribution.product_bebat')

                else:

                    contribution_product = self.env.ref('bebat_contribution.product_recupel')


                # Check if contribution line already exists

                existing = order.order_line.filtered(lambda l: l.product_id == contribution_product)

                if not existing:

                    self.env['sale.order.line'].create({

                        'order_id': order.id,

                        'product_id': contribution_product.id,

                        'name': contribution_product.name,

                        'product_uom_qty': 1,

                        'price_unit': contribution_product.lst_price,

                        'tax_id': [(6, 0, contribution_product.taxes_id.ids)],

                    })

        return lines


Hope it helps.



Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
jul 24
1447
1
sept 24
1538
2
ene 23
6948
0
feb 21
2788
0
mar 17
3800