Skip to Content
Menú
This question has been flagged
1 Respondre
1099 Vistes

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
Best Answer

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
Related Posts Respostes Vistes Activitat
1
de jul. 24
1440
1
de set. 24
1530
2
de gen. 23
6940
0
de febr. 21
2784
0
de març 17
3791