Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3345 Переглядів

Hi everyone,

I created a new model in odoo15 to create products. This model is completely separate from the existing product.product and product.template models (I don’t want to deal with their existing fields and functions and need to add many new ones).

Now I would like to create invoices based on these products, and in odoo13 it worked to simply create a new class that inherits the existing account.move.line and redefines the product_id field like this:


class CustomAccountMoveLine(models.Model):
    """Create Class for all V-Label invoice lines."""
    _inherit = 'account.move.line'
    _description = 'Custom Invoice Lines'
    
   product_id = fields.Many2one('MyCustomModule', string="Custom Product")
(...)

(I also had to add some fields to my custom module and change the _get_computed_price_unit function in account.move.line to make it work)


Now I can select the products correctly in my invoice lines and their quantity, prices, taxes, labels etc. are computed correctly. But when I click on “save”, I get the following error message:


Missing Record

Record does not exist or has been deleted.

(Record: product.product(1,), User: 2)

This happens, because in the Sales module I don’t have any record in the ‘product.product’ class - and I don’t want to have those, because after all I have my own product module. But why does this happen? Why is account.move(.line) still looking for product.product when I click the save button, even though everything up to that point is working fine? Also, why did this work in odoo13 but not odoo15? Could anyone please enlighten me?


Another approach I tried was to inherit the product module in my custom module:

_inherit = ‘product.product’

But when I try to upgrade my module, I get this database error below which I don’t know how to solve. Do I need to hack the database for this? Thank you very much in advance!

psycopg2.errors.UndefinedColumn: column "MyCustomModule_product_id" referenced in foreign key constraint does not exist
Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
вер. 24
3417
1
бер. 22
3212
3
лист. 23
5459
0
квіт. 23
2754
0
трав. 24
2839