wizard: on change trigger raises error in audittrail

Bug #448622 reported by Ferdinand
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Undecided
Unassigned

Bug Description

branch-server 1875
branch-addons official 2384
branch-addons chricar_5.0_price_unit 2486
trunk-extra-addons 3800

Trying to modify account/wizard/wizard_pay_invoice.py to fetch the matching period after changing the date

Environment Information :
System : Linux-2.6.27.29-0.1-default-x86_64-with-SuSE-11.1-x86_64
OS Name : posix
LSB Version: core-2.0-noarch:core-3.2-noarch:core-2.0-x86_64:core-3.2-x86_64:desktop-3.2-amd64:desktop-3.2-noarch:graphics-2.0-amd64:graphics-2.0-noarch:graphics-3.2-amd64:graphics-3.2-noarch
Distributor ID: SUSE LINUX
Description: openSUSE 11.1 (x86_64)
Release: 11.1
Codename: n/a
Operating System Release : 2.6.27.29-0.1-default
Operating System Version : #1 SMP 2009-08-15 17:53:59 +0200
Operating System Architecture : 64bit
Operating System Locale : en_US.UTF8
Python Version : 2.6.0
OpenERP-Client Version : 5.0.6
Last revision No. & ID :Bazaar Package not Found !Traceback (most recent call last):
  File "/home/terp/OpenERP/branch/server/5.0/bin/netsvc.py", line 244, in dispatch
    result = LocalService(service_name)(method, *params)
  File "/home/terp/OpenERP/branch/server/5.0/bin/netsvc.py", line 73, in __call__
    return getattr(self, method)(*params)
  File "/home/terp/OpenERP/branch/server/5.0/bin/addons/audittrail/audittrail.py", line 334, in execute
    object_name=obj._name
AttributeError: 'NoneType' object has no attribute '_name'

***** the modifed code ************

pay_form = '''<?xml version="1.0"?>
<form string="Pay invoice">
    <field name="amount"/>
    <newline/>
    <field name="name"/>
    <field name="date" on_change="onchange_date(date)"/>
    <field name="journal_id"/>
    <field name="period_id"/>
</form>'''

pay_fields = {
    'amount': {'string': 'Amount paid', 'type':'float', 'required':True},
    'name': {'string': 'Entry Name', 'type':'char', 'size': 64, 'required':True},
    'date': {'string': 'Payment date', 'type':'date', 'required':True},
    'journal_id': {'string': 'Journal/Payment Mode', 'type': 'many2one', 'relation':'account.journal', 'required':True, 'domain':[('type','=','cash')]},
    'period_id': {'string': 'Period', 'type': 'many2one', 'relation':'account.period', 'required':True},
}

def onchange_date(self, cr, uid, date, context=None):
    period_id = False
    if date:
        pool = pooler.get_pool(cr.dbname)
        period_ids= pool.get('account.period').search(cr,uid,[('date_start','<=',date),('date_stop','>=',date )])
        if len(period_ids):
             period_id=period_ids[0]
    return{'period_id':period_id}

Revision history for this message
Ferdinand (office-chricar) wrote :
Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) wrote :

Hello,

onchange is possible in wizard with osv.osv_memory class object.
The eg is exist in account module company.py file -> class company_setup.

Hope this will help you.

Thanks.

Revision history for this message
Ferdinand (office-chricar) wrote :

If I do understand correctly this means to rewrite the wizard which seems to me less a technical than an origanizational question.

If I (and others) do rewrite trigger using osv_memory it would be necessary to integrate these rewrites ASAP into the mainstram distribution

we should set up a procedure to do so because it seams to me to break backwards compatibility.

Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Hello Ferdinand,

I raised exactly this issue 2 days ago with Fabien. I said that Tiny is not going to have the power to rewrite it all alone, neither would it be good them carrying all the dev effort.

Ferdinand: as you can read here: https://bugs.launchpad.net/openobject-addons/+bug/435160
I wanted quite the same thing as you: fetch the period on data change (see last patch). But because old wizard don't support on_change, I made the trade-off of dropping the period field completely...

My point is that, as you say, THE COMMUNITY CAN DO IT, but provided, Tiny will TEST AND INTEGRATE. old wizard also have other issues, like lack of extensibility by third party modules. Recently, for instance I could make the effort to refactor the partial picking wizard or the reconcile wizard, because I was needing too. But just because Tiny stated no clear contrib process for this and because trunk branches were abandoned and messed up, I didn't do this effort and went for yet one more ugly copy/paste.

BTW, sometimes (not here), it's not even required to move to osv_memory already, just moving code from old wizard code back to the real OOP business objects they belong too often solve the extensibility issue. So for stable 5.0, I advise doing this as often as possible rather than rewriting using osv_memory which would be better done in trunk. Of course, here this is one of those case where osv_memory might be justified even on 5.0 stable.

Please Ferdinand and vra, tell us how do you see the community doing that. Can we expect this to be committed in 5.0 stable? at least a shortlist of annoying wizards? How Tiny will test carefully?
You can also contact me on r-v-a-l-y-i-@-akretion.com (without the "-") to discuss it.

Regards,

Revision history for this message
Ferdinand (office-chricar) wrote :
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Closing the bug as improvements have taken place in trunk.
Interrupt me if something is missing.
Thanks to community for the care taken.

Changed in openobject-server:
status: New → Fix Released
milestone: none → 6.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.