Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

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

By
samba
on 7/25/14, 3:45 AM 1,326 views

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 ..........................................................

 

 

 

1

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 7/25/14, 4:13 AM

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.

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

samba
on 7/25/14, 5:57 AM

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

Ludo - Neobis
on 7/25/14, 6:21 AM

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

samba
on 7/25/14, 7:02 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/25/14, 3:45 AM
Seen: 1326 times
Last updated: 3/16/15, 8:10 AM