Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Create a module that can be inherited to add a common field in other custom modules

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
inheritanceodoo16features
3 Replies
5346 Rodiniai
Portretas
ChrisB_USA

I want to add a field to several models which is the date of the weekly accounting period (weekending_date).  Originally I added this field (and a function to set the value) in each model where I required the field.  This resulted in the calculation function being duplicated in several places.

I would like to create a single module that defines the field and the function to calculate it, which I can then inherit in each model where I need it.  That way I only have the function defined once and have consistency across all models.

However, can I do this without it creating a table with just that one field in it?  

When I inherit the module, I want the field to be added into the main model where I need to use the field.  For example

Model account_move should have weekending_date added to it.

Model sale_order should have weekending_date added to it.

Any suggestions for how to do this correctly?



0
Portretas
Atmesti
ChrisB_USA
Autorius

Thank you. I think this is correct. I have implemented my first AbstractModel.

Portretas
Mai Chi Trung
Best Answer

I believe that is what AbstractModel is used for.

0
Portretas
Atmesti
Portretas
Ashish Hirpara
Best Answer

To add a field to multiple models and define a calculation function for the field in a single module, you can create a new module and use the _inherit attribute in the module's manifest file to inherit the models that you want to add the field to.

In the new module, you can define the field and the calculation function for the field in the fields.py file. For example, you can create a fields.py file with the following content:

from odoo import fields, models

class WeekendingDate(fields.Date):
    def _compute_weekending_date(self):
        # Code to calculate the weekending date
        pass

In this code, the WeekendingDate class is a subclass of the fields.Date class, and it defines a _compute_weekending_date method that can be used to calculate the weekending date.

Next, in the module's manifest file, you can use the _inherit attribute to inherit the models that you want to add the weekending date field to, and add the weekending date field to the models using the fields.Date class. For example, you can add the following lines to the manifest file:

'_inherit': ['account.move', 'sale.order'],

'fields': {
    'weekending_date': fields.Date('Weekending Date', compute='_compute_weekending_date'),
}

In this code, the _inherit attribute is used to inherit the account.move and sale.order models, and the fields attribute is used to add the weekending_date field to the models. The weekending_date field is defined using the fields.Date class, and it has a compute attribute that specifies the _compute_weekending_date method as the calculation function for the field.

By using the _inherit attribute and the fields attribute in this way, you can add the weekending date field to multiple models in a single module, and define a calculation function for the field that will be used consistently across all the models. This will allow you to avoid duplicating the calculation function in multiple places, and ensure consistency across all the models that have the weekending date field.

0
Portretas
Atmesti
ChrisB_USA
Autorius

Thank you very much Ashish. This was helpful. However on attempting to implement it, I was not able to use '_inherit' and 'fields' in the manifest file. That did not work and those properties are not listed in the official documentation for the syntax and properties in the manifest file.

Possibly that was from an earlier version of odoo?

In the end I implemented this as an AbstractModel, which contains the method to calculate the weekending_date. That model is then inherited by each of the models that require the weekending date.

Portretas
Adil Akbar
Best Answer

Please check the following link for custom module:

https://youtu.be/Xya_fCNr6tw

Thanks & Regards

0
Portretas
Atmesti
Enjoying the discussion? Don't just read, join in!

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

Registracija
Related Posts Replies Rodiniai Veikla
Odoo 16 ce: Inheritance of View to move a field from a group to another
inheritance odoo16features
Portretas
Portretas
Portretas
2
liep. 23
4888
How to conditionally replace field on inherited document and customer preview Solved
inheritance replace odoo16features
Portretas
Portretas
1
geg. 23
4094
how to inherit form in odoo 16 Solved
form inheritance odoo16features
Portretas
Portretas
1
kov. 23
4364
DeprecationWarning: The longpolling-port is a deprecated alias to the gevent-port option, please use the latter Solved
odoo16features
Portretas
Portretas
Portretas
Portretas
Portretas
5
rugs. 25
24300
How to Add wizard under print button inside the form view.
odoo16features
Portretas
Portretas
Portretas
Portretas
3
rugp. 25
3709
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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