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

overwriting methods create/write with one2many object

Odoberať

Get notified when there's activity on this post

This question has been flagged
many2onecreatev7objectoverwriting
2 Replies
11656 Zobrazenia
Avatar
N

In the view of the creation of a sale order, i put a number of section for each sale order line (a section allows me to decompose the sale order into multiple parts). When i create the sale order, i want the sale order section to be created too, with the same number i have put in the view. I've heard about overwriting create/write methods but i don't know how to do. Thanks, here is a part of my code :

class sale_order_line(osv.osv):

_name = 'sale.order.line'
_inherit = 'sale.order.line'

_columns = {
            'section_id': fields.many2one('sale.order.section', 'n° section', required=False, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]}),
            'number_section': fields.related('section_id', 'number', type='integer', string='N° section', store=False)
}

class sale_order_section(osv.osv):

_name = 'sale.order.section'
_columns = {
            'order_line': fields.one2many('sale.order.line', 'section_id', 'Order Lines', readonly=False),
            'number': fields.integer('n° section', help='permet de décomposer le devis en sous-sections'),
            'order_id': fields.related('order_line', 'order_id', type="many2one", relation='sale.order', string="Order", readonly=True, required=True),
}
0
Avatar
Zrušiť
Avatar
ClueLogics Technologies Pvt. Ltd.
Best Answer

Hi n@ilyk

as your Q, you can do like below :

you have inherit sale.order then put these 2 method

def create(self,cr,uid,vals,context=None):

id=super(sale_order,self).create(cr,uid,vals,context)</t>
cid=self.pool.get('sale.order.section').create(cr,uid,{'order_id':id,'number':'sec0001'})
for i in self.browse(cr,uid,id).order_line:

self.poo.get('sale.order.line').write(cr,uid,[i.id],{'section_id':cid})
return id

Thanks

4
Avatar
Zrušiť
N
Autor

Sorry : where i put this code ? in the sale_order_section class ?

ClueLogics Technologies Pvt. Ltd.

in your inherited sale.order

N
Autor

ok but i don't understand where 'sec0001' come from . In fact, for each order line i have a column "number" where i put the number of section associated to the order line. Also, if i put the same number for 3 order lines for example, just one section has to be created. Thanks for your help

ClueLogics Technologies Pvt. Ltd.

it was just a string which i put it , you can use your own no,,, for number in order line , i think you no need it because you have already a section Id , so why NUMBER ..... even you should use name of filed number as "name" then you can see section number in section Id , then you never need number in order line ,,,, as we have record id

N
Autor

Yes, it is the problem : i try to do 'number': order_line.number but it doesn't work. And a sale order is decomposed into multiples sections and here you create only one section ? I have number because if i write the same number for differents order lines, only one section is created

ClueLogics Technologies Pvt. Ltd.

one sale order as one section Id am i right ??

N
Autor

no : one sale order has multiples sections (a section is a group of invoice lines), that is why i use a number ^^. However, a sale order line is associated with only one section

Avatar
vim24
Best Answer

To override the create method just put your own create method in your sale.order.line class, in the following format:

    def create(self, cr, uid, vals, context=None):
         # Your additional code here
         return super(sale_order_line,self).create(cr,uid,vals,context)

The super(...) will ensure the original create method is still called and creates the object, while you code can add in any additional functionality you need.

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
Related Posts Replies Zobrazenia Aktivita
Create new Many2One records in @api.onchange method
many2one create onchange
Avatar
Avatar
1
aug 22
8903
change many2one object field from another object
many2one orm object
Avatar
Avatar
Avatar
5
okt 18
7524
Write method called in the create method
create v7 write
Avatar
Avatar
1
mar 15
8884
Override create on model with no create method?
create v7 inherit
Avatar
Avatar
1
mar 15
7351
many2one link between 2 classes
many2one v7 id
Avatar
Avatar
1
mar 15
5673
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