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

How to create and save my own Sale.Order model?

Odoberať

Get notified when there's activity on this post

This question has been flagged
sale.order.linesale.order12.
8963 Zobrazenia
Avatar
thanhps

Hi, 

I would like to copy and create my own new sale.order model and save data into a separate table in database. Therefore, I am using '_inherit' with '_name' in new model.

However, sale.order also include sale.order.line then I create my own new 'sale.order.line' as above.

When I tried to click Save button, I got the error below: 

-> raise TypeError("Mixing apples and oranges: %s - %s" % (self, other))

Here is my source code

class MyOrder(models.Model):
_name = "my.order"
_inherit = 'sale.order'
_description = "Sale Order"

order_line = fields.One2many('my.order.line', 'order_id', string='Order Lines',
states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True,
auto_join=True)
state = fields.Selection([
('draft', 'Draft'),
('sale', 'Sales Order'),
('done', 'Locked'),
('cancel', 'Cancelled'),
], string='Status', readonly=True, copy=False, index=True, track_visibility='onchange', track_sequence=3,
default='draft')

@api.model_cr
def init(self):
self._cr.execute("""
ALTER TABLE public.my_order ALTER COLUMN warehouse_id DROP NOT NULL;
ALTER TABLE public.my_order ALTER COLUMN picking_policy DROP NOT NULL;
ALTER TABLE public.my_order ALTER COLUMN partner_invoice_id DROP NOT NULL;
ALTER TABLE public.my_order ALTER COLUMN partner_shipping_id DROP NOT NULL;
ALTER TABLE public.my_order ALTER COLUMN team_group DROP NOT NULL;
""")

@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
if 'company_id' in vals:
vals['name'] = self.env['ir.sequence'].with_context(force_company=vals['company_id']).next_by_code(
'my.order') or _('New')
else:
vals['name'] = self.env['ir.sequence'].next_by_code('my.order') or _('New')

# Makes sure 'pricelist_id' are defined
if any(f not in vals for f in ['pricelist_id']):
partner = self.env['res.partner'].browse(vals.get('partner_id'))
vals['pricelist_id'] = vals.setdefault('pricelist_id',
partner.property_product_pricelist and partner.property_product_pricelist.id)
# Change state of order to 'sale'
vals['state'] = 'sale'
vals['date_order'] = fields.Date.today()
return super(MyOrder, self).create(vals)

​
class MyOrderLine(models.Model):
_name = 'my.order.line'
_inherit = 'sale.order.line'
_description = 'Sales Order Line'

order_id = fields.Many2one('my.order', string='Order Reference', required=True, ondelete='cascade',
index=True,
copy=False)

state = fields.Selection([
('draft', 'Draft'),
('sale', 'Sales Order'),
('done', 'Done'),
('cancel', 'Cancelled'),
], related='order_id.state', string='Order Status', readonly=True, copy=False, store=True, default='draft')

@api.model_cr
def init(self):
self._cr.execute("""
ALTER TABLE public.my_order_line ALTER COLUMN customer_lead DROP NOT NULL;
""")

# Override for non-checking inventory
@api.onchange('product_uom_qty')
def _onchange_product_uom_qty(self):
return {}

# Override for non-checking inventory
@api.onchange('product_uom_qty', 'product_uom', 'route_id')
def _onchange_product_id_check_availability(self):
return {}


Thank you for your help!

0
Avatar
Zrušiť
Niyas Raphy (Walnut Software Solutions)

Better you can use inherits the model sale.order such a way that while creating record it will get added in both models. By default in odoo, you will get example with the product.product model and product.template model.

In the product.product model there is a many2one relation to product.template model, and also product.product model is created using the _inherits

thanhps
Autor

But it inherits only fields not methods, right?

I still want to use some compute methods in sale.order to compute price or total.

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
Merge Same Item in Sale Order Line Solved
sale.order.line sale.order
Avatar
Avatar
Avatar
2
jan 24
6283
Combine inline editing with more detailed form view
sale.order.line sale.order
Avatar
0
jún 23
2770
ValueError: <class 'ValueError'>: "Expected singleton: sale.order.line(<NewId ref='virtual_117'>, <NewId ref='virtual_131'>)"
sale.order.line sale.order
Avatar
Avatar
1
dec 22
4201
How to update a custom field as "Margin" default from sale.order does, when some product of sale.order.line is updated/deleted.
sale.order.line sale.order
Avatar
0
apr 22
3225
How to get partner_id from sale.order.line? Solved
sale.order.line 12.
Avatar
Avatar
1
jún 19
9528
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