Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Field default do not work

Odebírat

Get notified when there's activity on this post

This question has been flagged
invoicedefaultinheritanceodoo12
4 Odpovědi
8736 Zobrazení
Avatar
Maks

I've been working on a module for interests. What I have to do is to make possible to create an invoice which has interests from overdue invoices as invoice lines. To do this, I need to pass few fields to another window with new invoice creation. Here is my problem. I tried to pass field value of invoice comment as a test. But when I add comment field with additional default, I noticed, that default is not read at all. When I edit this field in different way (e.g. I add readonly=False) then changes are visible. Only default do not work. Anyone know why?

Original field:

comment = fields.Text('Additional Information', readonly=True, states={'draft': [('readonly', False)]})


Class that inherit account.invoice:


class InterestNote(models.Model):
_inherit = 'account.invoice'
_translate = True

interest_paid = fields.Boolean(string='Are interests paid?', help='Boolean to see if interests are already paid.',
default=False)

@api.multi
def interest_note(self):
_logger.info(f'ID FAKTURY: {self.id}')
_logger.info(f'NUMER FAKTURY: {self.number}')
_logger.info(f'PARTNER: {self.partner_id}')
_logger.info(f'COMMENT: {self.comment}')
_logger.info(f'COMMENT TYP: {type(self.comment)}')
com = self.comment
_logger.info(f'COM: {com}')
_logger.info(f'COM TYPE: {type(com)}')

return {
'name': 'Create new interest note',
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'account.invoice',
'context': {'t_comment': com},
'target': 'new'
}

@api.model
def get_comment_test(self):
_logger.info('FUNKCJA TEST ROZPOCZYNA SIĘ')
test_com = self.env.context.get('t_comment')
_logger.info(f'TEST COM: {test_com}')
_logger.info(f'TEST COM TYPE: {type(test_com)}')

if not test_com:
test_com = ''

return test_com

comment = fields.Text('Additional Information', default=get_comment_test,
readonly=False, states={'draft': [('readonly', False)]})

Method interest_note works fine, it is callable but button and when I clicked it, the log messages appear normally. What should happen, is after clicking the button, new windows to create an invoice pop up, with filled comment field, after the invoice from which the button was clicked. When I write default='get_comment_test' it also do not work. So the get_comment_test method, but with default. Logger message from this method never showed up on logs. Funny thing is that in Odoo 11 I've done something almost identical and it worked. Only in 12 I have this issue. Anyone have an idea what is going on?

0
Avatar
Zrušit
Gleb

Here is an example (odoo v12):

Call new form and set three fields by default value (order_id, partner_id, order_line)

return {

'name': _('Check'),

'view_type': 'form',

'view_mode': 'form',

'res_model': 'check.purchase.order.lines',

'views': [

(form_view.id, 'form'),

],

'type': 'ir.actions.act_window',

'target': 'current',

'context': {

'default_order_id': self.id,

'default_partner_id': self.partner_id.id,

'default_order_line': self.get_unverified_record_ids()

},

Standard construction: write 'context': {'default_field_name': value}

In your example: write 'context': {'default_t_comment': com}

Maks
Autor

@Gleb I have no idea what are you writing. It has no connection to invoices... I tried to convert it to my example and it didn't work anyway. My question is simple really. Why it do not work? Show me error in my code, and write correction. Not entire examples, which are not connected to my issue and solving nothing.

Avatar
Maks
Autor Nejlepší odpověď

@Zbik

Hello. I tried adding view_id, because everything else I have the same (without target) and still it doesn't work. What I found interesting, is that on one field, my default works just fine. In comment it doesn't.


class InterestNote(models.Model):
_inherit = 'account.invoice'
_translate = True

interest_paid = fields.Boolean(string='Are interests paid?', help='Boolean to see if interests are already paid.',
default=False)
# tester = fields.Text(string='TEST', default=get_comment_test)

@api.multi
def interest_note(self):
_logger.info(f'ID FAKTURY: {self.id}')
_logger.info(f'NUMER FAKTURY: {self.number}')
_logger.info(f'PARTNER: {self.partner_id}')
_logger.info(f'COMMENT: {self.comment}')
_logger.info(f'COMMENT TYP: {type(self.comment)}')
com = self.comment
# ctx = dict(
# type='out_invoice',
# comment=com
# )
_logger.info(f'COM: {com}')
_logger.info(f'COM TYPE: {type(com)}')

# inv_obj = self.env['account.invoice']
# inv = inv_obj.create(ctx)
# _logger.info(f'ID FAKTURY INV: {inv.id}')
# return {'type': 'ir.actions.act_window_close'}

return {
'name': 'Create new interest note',
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'view_id': self.env.ref('account.invoice_form').id,
'res_model': 'account.invoice',
'context': {
'type': 'out_invoice',
'default_type': 'out_invoice',
'comment': com,
'default_comment': com
},
'target': 'current'
}

@api.model
def get_comment_test(self):
_logger.info('FUNKCJA TEST ROZPOCZYNA SIĘ')
test_com = self.env.context.get('comment')
_logger.info(f'TEST COM: {test_com}')
_logger.info(f'TEST COM TYPE: {type(test_com)}')

if not test_com:
test_com = '456'

return test_com

comment = fields.Text('Additional Information', default=get_comment_test,
readonly=True, states={'draft': [('readonly', False)]})
tester = fields.Text(string='TEST', default=get_comment_test)

Field comment is still without any values when new invoice, but field tester works. Why is that? It's so confusing right now, I really do not understand why in one field something works, but in another it doesn't.

0
Avatar
Zrušit
Zbik

Steps:

1. Your module set comment - for example: comment = "XYZ"

2. Now is started method in module sale

3. Field invoice comment is set in module sale - in this case comment = self.env.user.company_id.sale_note

4. sale_note is porobably False => in effect comment = False

Maks
Autor

What? My module is inheriting an "account.invoice", and field comment is also in this module. What I'm trying to do is to create an invoice from within another invoice, and pass a field to newly created one. It has nothing to do with sale. And I already told my issue few times, I really don't know why people on this forum so often act like they don't know the question, but they give an answer anyway. My methods works. Method get_comment_test works. In field tester everything seems fine, default method get_comment_test work. This do not work only in comment. default for comment do not work, where change in readonly is working, so only this default on this particular field cause problems. Does anyone know why, and how to solve it?

Zbik

If you have the module sale installed and field "Default Terms & Conditions" in sale config is checked, value in field comment depends on it. Too bad you do not understand. Insert "LOREM IPSUM" in Default Terms & Conditions and see on effect.

Avatar
Zbik
Nejlepší odpověď

Your problem is probably related to something else.
In module sele field comment is redefined too.
See:
def _default_comment(self):
invoice_type = self.env.context.get('type', 'out_invoice')
if invoice_type == 'out_invoice' and self.env['ir.config_parameter'].sudo().get_param('sale.use_sale_note'):
return self.env.user.company_id.sale_note

comment = fields.Text(default=_default_comment)

If your module not depends on sale then result in this field may be different than you expect .

PS. It is easier to use (if sale not inherit, without redefinition the commment field):  

return {
  'name': 'Create new interest note',
  'type': 'ir.actions.act_window',
  'view_type': 'form',
  'view_mode': 'form',
  'view_id': self.env.ref('account.invoice_form').id,
  'res_model': 'account.invoice',
  'context': {'type':'out_invoice', 'default_type': 'out_invoice', 'default_comment': com },
  'target': 'new'
}


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

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Override journal default on account_invoice
invoice default inheritance models
Avatar
0
úno 16
4210
Override and Change the middle of a function Vyřešeno
inheritance odoo12
Avatar
Avatar
Avatar
Avatar
7
čvn 24
26129
Function inheritance
inheritance odoo12
Avatar
0
zář 20
2981
Open an invoice using XMLRPC
invoice odoo12
Avatar
Avatar
2
kvě 20
5811
How to modify validated invoice?
invoice odoo12
Avatar
Avatar
Avatar
2
lis 18
4971
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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