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
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • 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
    Browse all Industries
  • 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
    • Services for Partners
    • 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

How to give edit rights to form when it is in certain state?

Odebírat

Get notified when there's activity on this post

This question has been flagged
workflowformedit
1 Odpovědět
7624 Zobrazení
Avatar
samba

I am trying to add "approve" state to the invoices. I did these changes.

I have inherited "account.invoice" module and view also.

previously invoice has "draft" "open" states i have added "validate" in between draft and open.Just i am updating the state when the user click on "act_validate" signal. It's working fine but i unable to edit the form when it is in "validate" state. Please help me using below code snippet.

......................................... model.py file.......................................................................................

class account_invlice_extension(osv.osv):
    _inherit = "account.invoice"
    def _paid_amount_in_company_currency(self, cr, uid, ids, name, args, context=None):
        if context is None:
            context = {}
        res = {}
        ctx = context.copy()
        for v in self.browse(cr, uid, ids, context=context):
            voucher = self.browse(cr, uid, v.id, context=ctx)
            res[voucher.id] =  self.pool.get('res.currency').compute(cr, uid, voucher.currency_id.id, voucher.company_id.currency_id.id, voucher.amount_total, context=ctx)
        return res
    def approve(self, cr, uid, ids):
        self.write(cr, uid, ids, {'state': 'validate'})
        return True

    _columns = {
        'state': fields.selection([
            ('draft','Draft'),
            ('proforma','Pro-forma'),
            ('proforma2','Pro-forma'),
            ('validate','Validate'),
            ('open','Open'),
            ('paid','Paid'),
            ('cancel','Cancelled'),
            ],'Status', select=True, readonly=True, track_visibility='onchange',
            help=' * The \'Draft\' status is used when a user is encoding a new and unconfirmed Invoice. \
            \n* The \'Pro-forma\' when invoice is in Pro-forma status,invoice does not have an invoice number. \
            \n* The \'Open\' status is used when user create invoice,a invoice number is generated.Its in open status till user does not pay invoice. \
            \n* The \'Paid\' status is set automatically when the invoice is paid. Its related journal entries may or may not be reconciled. \
            \n* The \'Cancelled\' status is used when user cancel invoice.'),
       'amount_toatl_cc':fields.function(_paid_amount_in_company_currency, type='float', digits_compute=dp.get_precision('Account'), string='Amount in Home Cur.',digits=(12,6)),
    
    }

   ................................... end of model.py...............................................................

.........................................view file..........................................................................

<openerp>
  <data>
    <record model="ir.ui.view" id="account_invoice_customer_extension">
        <field name="name">account.invoice.form</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_form"/>
        <field name="arch" type="xml">
            <xpath expr="/form/header/button[@name='invoice_cancel']" position="after">
                <button name="invoice_cancel" states="validate" string="Cancel Invoice" groups="base.group_no_one"/>
            </xpath>
            <xpath expr="/form/header/button[@name='invoice_open']" position="replace">
                <button name="invoice_open" states="validate" string="Approve" class="oe_highlight" groups="base.group_user"/>
            </xpath>
            <xpath expr="/form/header/button[@name='invoice_cancel']" position="before">
                <button name="invoice_approve" states="draft" string="Validate" class="oe_highlight" groups="base.group_user"/>
            </xpath>
            <xpath expr="/form/header/field[@name='state']" position="replace">
                <field name="state" widget="statusbar" nolabel="1" statusbar_visible="draft,validate,open,paid" statusbar_colors='{"proforma":"blue","proforma2":"blue"}'/>
            </xpath>
            <xpath expr="/form/sheet/notebook/page/group/field[@name='amount_total']" position="after">
                <field name="amount_toatl_cc" widget="monetary" options="{'currency_field':'company_id.currency_id'}"/>
            </xpath>
        </field>
    </record>
    <record model="ir.ui.view" id="account_invoice_supplier_extension">
        <field name="name">account.invoice.form</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_supplier_form"/>
        <field name="arch" type="xml">
            <xpath expr="/form/sheet/group/group[2]/field[@name='journal_id']" position="replace">
                  <field name="journal_id" groups="account.group_account_user"
                                on_change="onchange_journal_id(journal_id, context)" widget="selection"/>
                
<!--                <field name="amount_toatl_cc" widget="monetary" options="{'currency_field': 'company_id.currency_id'}"/>-->
            </xpath>
        </field>
    </record>
    <record model="ir.ui.view" id="account_invoice_supplier_tree_extension">
        <field name="name">account.invoice.form</field>
        <field name="model">account.invoice</field>
        <field name="inherit_id" ref="account.invoice_tree"/>
        <field name="arch" type="xml">
            <xpath expr="/tree/field[@name='amount_total']" position="after">
                <field name="amount_toatl_cc"/>
            </xpath>
        </field>
    </record>
<!--    work flow-->
    <record id="wkf" model="workflow">
            <field name="name">account.invoice.basic</field>
            <field name="osv">account.invoice</field>
            <field name="on_create">True</field>
        </record>
<!--    Activity-->

    <record model="workflow.activity" id="act_approve">
                    <field name="wkf_id" ref="wkf" />
                    <field name="name">approve</field>
                    <field name="action">approve()</field>
                    <field name="kind">function</field>
                    
   </record>
   <record id="act_draft" model="workflow.activity">
            <field name="wkf_id" ref="wkf"/>
            <field name="flow_start">True</field>
             <field name="split_mode">AND</field>
            <field name="name">draft</field>
        </record>
        <record id="act_open" model="workflow.activity">
            <field name="wkf_id" ref="wkf"/>
            <field name="name">open</field>
            <field name="action">action_date_assign()
action_move_create()
action_number()
invoice_validate()</field></record>

<!--    Transition-->
    <record model="workflow.transition" id="t256">
                    <field name="act_from" ref="act_draft" />
                    <field name="act_to" ref="act_approve" />
                    <field name="signal">invoice_approve</field>
    </record>
    <record id="t4" model="workflow.transition">
            <field name="act_from" ref="act_approve"/>
            <field name="act_to" ref="act_open"/>
            <field name="signal">invoice_open</field>
   </record>
    
  </data>
</openerp>

 

...................................................................END OF VIEW FILE ..........................................................

 

 

 

0
Avatar
Zrušit
Avatar
Ludo - 21South
Nejlepší odpověď

Check the original field in the views or in the py files. I think they all have the "states" attribute added to them. This means that unless you change that, they will only be editable in a certain state (most likely only "draft"). 

Change that into ["draft","validate"] and see if it works.

1
Avatar
Zrušit
samba
Autor

Thank you Ludo, this help me alot. But i unable to call parent class function in to model fields i.e . 'reference_type': fields.selection(super(account_invoice_extension, self)._get_reference_type, 'Payment Reference', required=True, readonly=True, states={'draft':[('readonly',False)]}), My class name is "account_invoice_extension". It is giving "NameError: name 'account_invoice_extension' is not defined " Error

Ludo - 21South

You forgot: _name = "account.invoice" (assuming you want your module to override the fields)

samba
Autor

Thank you Ludo, I follow the same. My problem solved

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
Hide Edit button
xml form edit
Avatar
0
pro 19
7225
Field editing after create a form Vyřešeno
fields form create edit
Avatar
Avatar
1
srp 23
2847
How to lock an object to users when there is another user who has opened a form to edit it? Vyřešeno
form user edit lock
Avatar
Avatar
1
čvc 21
11455
How to hide form Edit button depends on field value? Vyřešeno
form hide button edit
Avatar
Avatar
Avatar
Avatar
Avatar
4
pro 23
24213
multiple views in a single workflow
workflow views form v7
Avatar
Avatar
1
bře 15
5737
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