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

Hi guys,

After installed module base_address_city, I would like to create another field called District to have relationship Many2one to city_id (base_address_city)

My simple code:

(base_address_district.py)

...

class District(models.Model):

    _name = 'res.district'

    _description = 'District'

    _order = 'name'    

    name = fields.Char(String='District Name', required=True, translate=True, help='The full name of the district')

    zipcode = fields.Char("Zip")    

    city_id = fields.Many2one('res_city', 'City', required=True)


class Partner(models.Model):

    _inherit = ['res.partner']

    _name = 'res.partner'

    district = fields.Many2one('res.district', ondelete='restrict', string='district', index=True)

  

    @api.onchange('district_id')

    def _onchange_district_id(self):

        self.district = self.district_id.name

        self.zip = self.district_id.zipcode

        self.city_id = self.district_id.city_id

(base_address_district.xml)

...    
<record id="view_res_partner_extended_district_form" model="ir.ui.view">

        <field name="name">view_res_partner_extended_district_form</field>

        <field name="model">res.partner</field>

        <field name="inherit_id" ref="base.view_partner_form"/>

        <field name="arch" type="xml">

        <xpath expr="//field[@name='street2']" position="after">

        <field name="district" groups="base.group_no_one" placeholder="District..." />

        </xpath>

        </field>

        </record>

...

Then face the error:

...
psycopg2.ProgrammingError: relation "_unknown" does not exist LINE 1: SELECT "_unknown".id FROM "_unknown" ORDER BY "_unknown"."id...


By searching internet, there is few ppl found similar issue while adding a module that have relationship with base module or res module for example:

https://www.odoo.com/forum/help-1/question/weird-error-programmingerror-relation-unknown-does-not-exist-line-1-select-unknown-id-from-unknown-order-by-unknown-id-74185

Please help to suggest if there is solution and reason behind.

Avatar
Discard
Best Answer

hi

 city_id = fields.Many2one('res_city', 'City', required=True)

try changing this to

 city_id = fields.Many2one('res.city', 'City', required=True)

res_city to res.city


Avatar
Discard
Best Answer

add a breakpoint with condition self.comodel_name == '_unknown' in the file odoo/odoo/fields.py function update_db_foreign_keys and check what self referes to

Avatar
Discard
Author Best Answer

Hi Kevin,

I tried before posted question without delete database, it doesn't work.

Currently, I tried with delete database then re-install all related modules, it's working, many thinks for your suggestion. You gave me more confident that this way should work.


Noted: when checked database before posted question there is table res_city where I added a row:

 id |    name     | country_id | state_id | create_uid |        create_date         | write_uid |         write_date 

----+-------------+------------+----------+------------+----------------------------+-----------+----------------------------

  1 | Saphan-sung |        217 |      679 |          1 | 2018-05-14 10:30:27.965798 |         1 | 2018-05-14 10:30:27.965798

(1 row)

And try checked import path odoo.addons.base_address_city.models.res_city, its available.

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 24
343
1
Jan 24
1689
2
Mar 23
1024
3
Jun 20
8733
2
Mar 20
6927