Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

View extension and model inheritance

Odoberať

Get notified when there's activity on this post

This question has been flagged
2 Replies
6852 Zobrazenia
Avatar
Sebastián Seifert

Hi, 

I´m trying to create a base module with some other modules extending it, and adding more functionality to this base module.

In order to extend de base module, I´m using inheritance without changing the _name field, using only the field _inherit. (I´ll copy my code at the end).

To extend the views of the model I´m using extension inheritance.

Everything works fine the first time I install all modules, but when I try to update the base module, the server will throw and exception because it can´t find the fields from the subclases for the already extended view.

I´ve managed to make it work running an sql script that erase this views. But i would like not to do that, just get the base module updated clicking on the update button of the module. 

I´ll copy my code now.

class document(models.Model):
 
     _name = 'document_control_base.document'

       @api.model
     def _get_resources_list(self):
            model_obj = self.env['document_control_base.resource_type']
            return model_obj._get_resources_list()
        
       STATE_SELECTION = [('active', 'Vigente'),('to_expire', 'Proximo a vencer'),('expired', 'Vencido')]

      name = fields.Char("Nombre",readonly=True,store=True,compute='_compute_name')
  document_name_id = fields.Many2one("document_control_base.document_name","Nombre del documento")
document_condition_ids = fields.Many2many("document_control_base.document_condition", "document_condition_rel", "document_id", "condition_id", "Condiciones del documento")
res_partner_id = fields.Many2one("res.partner",string="Empresa/Recurso Externo")
...

class document(models.Model):
    _inherit = 'document_control_base.document'
    fleet_vehicle_id = fields.Many2one("fleet.vehicle",string="Vehiculo")

    @api.one
    @api.depends('file_name','res_partner_id','document_name_id','state','fleet_vehicle_id')
    def _compute_name(self):
        super(document, self)._compute_name()
    
    resid = self.fleet_vehicle_id.name if self.fleet_vehicle_id.name else ''
    self.name = resid.title() + self.name
...
<record id="document_control_base.document_form" model="ir.ui.view">
<field name="model">document_control_base.document</field>
<field name="arch" type="xml">
<form string="Documentos">
<sheet>
<label for="name" class="oe_edit_only" />
<h1>
<field name="name" class="oe_edit_only" />
</h1>
<group>
<field name="res_type" class="oe_edit_only oe_inline" widget="radio"/>
<field name="res_partner_id" domain="['|','&amp;','&amp;','&amp;',('is_company', '=', False),('parent_id', '!=', False),
('active', '=', True),('employee','=',False),'&amp;','&amp;','&amp;',('is_company', '=', True),('parent_id', '=', False),('active', '=', True),('employee','=',False)]"
attrs="{'invisible':[('res_type', '!=', 'res.partner')]}" class="oe_edit_only"/>
</group>
<group>
<group>
<field name="file_binary" filename="file_name" />
<field name="file_name" class="oe_inline oe_right" invisible="1" />
<field name="document_name_id" domain="[('res_type','=',res_type)]"/>
<field name="document_condition_ids" widget="many2many_tags" />
<field name="description" />
</group>
</group>
<group>
<field name="no_expiration" />
<field name="expiration_id"
attrs="{'invisible':[('no_expiration','=',True)]}"
context="{'form_view_ref': 'document_control_base.expiration_form','resources':'expirations','name':'Vencimiento:','res_partner_id':res_partner_id,'document_name_id':document_name_id}" />
<field name="in_renewal" />
<field name="state" readonly="1" class="oe_edit_only" />
</group>
</sheet>
</form>
</field>
</record>
....
<record model="ir.ui.view" id="document_control_base.document_form_fleet">
<field name="model">document_control_base.document</field>
<field name="inherit_id" ref="document_control_base.document_form" />
<field name="arch" type="xml">
<field name="res_partner_id" position="after">
<label for="fleet_vehicle_id" attrs="{'invisible':[('res_type', '!=', 'fleet.vehicle')]}" class="oe_edit_only" />
<field name="fleet_vehicle_id" attrs="{'invisible':[('res_type', '!=', 'fleet.vehicle')]}" class="oe_edit_only"/>
</field>
<field name="expiration_id" position="attributes">
<attribute name="context">{'form_view_ref': 'document_control_base.expiration_form','resources':'expirations','name':'Vencimiento:','res_partner_id':res_partner_id,'fleet_vehicle_id':fleet_vehicle_id,'document_name_id':document_name_id}</attribute><!-- <attribute name="context" add=" py.PY_setItem(py.evaluate(expr.first, context),'fleet_vehicle_id', fleet_vehicle_id)" separator=" "></attribute> -->
</field>
</field>
</record>
0
Avatar
Zrušiť
Ameera PP

why using 2 classes here?

Sebastián Seifert
Autor

The first is from the base module. The second is from the extending module, there are several modules extending the base class. Fleet is only one. And their are installed separately. I can´t erase the answer. Sorry.

Avatar
Sebastián Seifert
Autor Best Answer

The first is from the base module. The second is from the extending module, there are several modules extending the base class. Fleet is only one. And their are installed separately. 

0
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now