Skip to Content
Menu
This question has been flagged
3 Replies
2777 Views

Hello, I am created a module to automatically create a mrp production order, create a bill of materials for it if it still doesn't exists and the convert a product to another when I receive it. Everything was working fine, the module was deployed and it is working perfectly on production. 

However, I am having problems trying to run the module on local after dumping the database. 

The code that creates the bill of material for a given product_id is the following:

class MrpBOM(models.Model):
    _inherit = "mrp.bom"

    @api.multi
    def get_product_bom(self, product_id):
        bom_id = self.search([('product_id','=',product_id.id)], limit =1)
        if not bom_id:
            bom_id = self.create_bom_for_product(product_id)
        return bom_id

    @api.multi
    def create_bom_for_product(self, product_id):
        transformation = self.env['mrp.transformation'].search([('product_id','=',product_id.id)],limit = 1)
        bom_id = self.create({
            'product_tmpl_id': product_id.product_tmpl_id.id,
            'product_id': product_id.id,
            'product_qty': 1,
        })

        product_qty = product_id.weight
        if transformation.source_product.uom_id.id == 1:
            product_qty = 1

     bom_line = self.env['mrp.bom.line'].create({
        'product_id': transformation.source_product.id,
        'product_qty': product_qty,
        'bom_id': bom_id.id
     })
    bom_id.write({
        'bom_line_ids': [(6,0,[bom_line.id])]
     })

    return bom_id 

When I try to run it locally, I get the following error:

Erro:

Odoo Server Error


Traceback (most recent call last):

  File "/usr/lib/python3/dist-packages/odoo/http.py", line 650, in _handle_exception

    return super(JsonRequest, self)._handle_exception(exception)

  File "/usr/lib/python3/dist-packages/odoo/http.py", line 310, in _handle_exception

    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])

  File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 87, in reraise

    raise value

  File "/usr/lib/python3/dist-packages/odoo/http.py", line 692, in dispatch

    result = self._call_function(**self.params)

  File "/usr/lib/python3/dist-packages/odoo/http.py", line 342, in _call_function

    return checked_call(self.db, *args, **kwargs)

  File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper

    return f(dbname, *args, **kwargs)

  File "/usr/lib/python3/dist-packages/odoo/http.py", line 335, in checked_call

    result = self.endpoint(*a, **kw)

  File "/usr/lib/python3/dist-packages/odoo/http.py", line 936, in __call__

    return self.method(*args, **kw)

  File "/usr/lib/python3/dist-packages/odoo/http.py", line 515, in response_wrap

    response = f(*args, **kw)

  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 938, in call_button

    action = self._call_kw(model, method, args, {})

  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 926, in _call_kw

    return call_kw(request.env[model], method, args, kwargs)

  File "/usr/lib/python3/dist-packages/odoo/api.py", line 689, in call_kw

    return call_kw_multi(method, model, args, kwargs)

  File "/usr/lib/python3/dist-packages/odoo/api.py", line 680, in call_kw_multi

    result = method(recs, *args, **kwargs)

  File "/usr/lib/python3/dist-packages/odoo/addons/stock/wizard/stock_immediate_transfer.py", line 34, in process

    pick_to_do.action_done()

  File "/home/arthur/theVelopment/raizs/raizs/vtex_connector/models/connector_picking.py", line 70, in action_done

    self.env['mrp.production'].transform_products(self)

  File "/home/arthur/theVelopment/raizs/raizs/vtex_connector/models/raizs_mrp.py", line 103, in transform_products

    self.transform_source_product(move_line_id.product_id, move_line_id.qty_done, lot_id = move_line_id.lot_id)

  File "/home/arthur/theVelopment/raizs/raizs/vtex_connector/models/raizs_mrp.py", line 109, in transform_source_product

    self.produce_product(transform_id, quantity_done, lot_id)

  File "/home/arthur/theVelopment/raizs/raizs/vtex_connector/models/raizs_mrp.py", line 224, in produce_product

    production_order = self.simulate_order(transformation_id.product_id, quantity_to_produce, lot_id)

  File "/home/arthur/theVelopment/raizs/raizs/vtex_connector/models/raizs_mrp.py", line 176, in simulate_order

    bom_id = self.env['mrp.bom'].get_product_bom(product_id)

  File "/home/arthur/theVelopment/raizs/raizs/vtex_connector/models/raizs_mrp.py", line 65, in get_product_bom

    bom_id = self.create_bom_for_product(product_id)

  File "/home/arthur/theVelopment/raizs/raizs/vtex_connector/models/raizs_mrp.py", line 74, in create_bom_for_product

    'product_qty': 1,

  File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_thread.py", line 236, in create

    thread = super(MailThread, self).create(values)

  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3372, in create

    record = self.browse(self._create(old_vals))

  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3465, in _create

    cr.execute(query, tuple(u[2] for u in updates if len(u) > 2))

  File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 155, in wrapper

    return f(self, *args, **kwargs)

  File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 232, in execute

    res = self._obj.execute(query, params)

psycopg2.ProgrammingError: relation "mrp_bom_id_seq" does not exist

LINE 1: ...uid", "create_date", "write_date") VALUES(nextval('mrp_bom_i...

                                                         

Can anyone point out what I might be doing wrong?

Avatar
Discard
Best Answer

Hello Arthur,

Before restoring the DB you have to replace one text from the .SQL file

The text is AS INTEGER,  you replace this with EMPTY SPACE.

Probably This is a bug in Odoo new version, I am also having this problem. I have solved this with AS INTEGER text replace. now it's working for me.

Avatar
Discard
Author

Hello, I I am having the same problem again... I can't tell exactly what should I replace. Can you provide me some example or print screen?

Author Best Answer

Thank you @subbarap, I didn't solve by using your solution, but didn't try it. Where would I find this .SQL file?

I ended up solving the problem by removing odoo and psql and then reinstalling it again.

Avatar
Discard
Author Best Answer

Thank you @subbarap, I didn't solve by using your solution, but didn't try it. Where would I find this .SQL file?

I ended up solving the problem by removing odoo and psql and then reinstalling it again.

Avatar
Discard
Related Posts Replies Views Activity
1
Jan 20
3294
0
Feb 19
2726
0
Nov 18
2026
0
Feb 16
2842
1
Aug 15
3628