Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

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

Subscriure's

Get notified when there's activity on this post

This question has been flagged
workflowformedit
1 Respondre
7623 Vistes
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
Descartar
Avatar
Ludo - 21South
Best Answer

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
Descartar
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!

Registrar-se
Related Posts Respostes Vistes Activitat
Hide Edit button
xml form edit
Avatar
0
de des. 19
7213
Field editing after create a form Solved
fields form create edit
Avatar
Avatar
1
d’ag. 23
2845
How to lock an object to users when there is another user who has opened a form to edit it? Solved
form user edit lock
Avatar
Avatar
1
de jul. 21
11454
How to hide form Edit button depends on field value? Solved
form hide button edit
Avatar
Avatar
Avatar
Avatar
Avatar
4
de des. 23
24213
multiple views in a single workflow
workflow views form v7
Avatar
Avatar
1
de març 15
5735
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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