Ir al contenido
Menú
Se marcó esta pregunta

I'm new to Odoo, and using Odoo 13.

There is a sale module in my company, and one product depends to another. So when we create a new invoice (account.move), we must add new invoice line (account.move.line) of depended product.

My code goes like:

         new_line = invoice_line_ids.new({
                    'move_id': self.id,
                    'product_id': product_id.id,
                    '_dependency': True,
                    'quantity': 1.0,
                    'sequence': sequence,
                    })

But there is another problem: my new account move line did not compute in account_move.amount_untaxed and account_move.amount_total. For sometimes passing by, I found this function in model AccountMove for calculating those 2 fields:

        @api.depends(
            'line_ids.debit',
            'line_ids.credit',
            'line_ids.currency_id',
            'line_ids.amount_currency',
            'line_ids.amount_residual',
            'line_ids.amount_residual_currency',
            'line_ids.payment_id.state')
        def _compute_amount(self):


No matter what I did, calling it in my code, it just wouldn't goes as expected. But when I ran debug mode in my ide, anytime a new account.move.line added, it triggered.

May I ask why?

Avatar
Descartar

Would it not be better to create a package that includes both products and sell that instead? As Fabien managed to chip in, starting by brute force customisation defeats the holistic approach so try this option or check more advanced modules that do similar.

Mejor respuesta

What about using standard features instead of doing custom developments? If you start hacking too much the way invoices or sales work in standard, you might face unexpected side effects with other modules / wrong behaviours.

Usually, extra products are added when doing the quotation / order, not when producing the invoice. To do so, there are several mechanism, depending on the exact need:

- you can use "Optional Products" : when adding a specific product to the sale order, Odoo will open a popup to propose the user to add some extra product.

- you might use variants when the extra product is required. In such case, if you want to split the main product into 2 different ones at inventory level, you can use kits on this variant.

- there is also others mechanisms to add a product at the invoice level: 1/ adding delivery costs, when delivery is charged based on shipped quantities or 2/ adding costs in the order (could come from expenses, or purchase orders). This last one is the mechanism used to charge expenses based on time and materials.

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
may 25
9199
1
jul 23
1273
1
abr 20
60
0
abr 20
10
2
mar 22
6549