Hello,

from osv import osv, fields

class person_state(osv.osv):
        """(NULL)"""
        _name = 'person.state'
        _columns = {
                'name': fields.char('State code',size=32),
                'state': fields.char('State',size=64),
        }
person_state()

class person_district(osv.osv):
        """(NULL)"""
        _name = 'person.district'
        _columns = {
                'name': fields.char('District Code',size=32),
                'district': fields.char('District',size=64),
                'statename': fields.many2one('person.state','State 
Code',size=64),
        }
person_district()

class person_taluka(osv.osv):
        """(NULL)"""
        _name = 'person.taluka'
        _columns = {
                'name': fields.char('Taluka Code',size=32),
                'taluka': fields.char('Taluka Name',size=64),
                'districtname': fields.many2one('person.district','District 
Code',size=32),
        }
person_taluka()

class person_village(osv.osv):
        """(NULL)"""
        _name = 'person.village'
        _columns = {
                'name': fields.char('Village Code',size=32),
                'village': fields.char('Village Name',size=64),
                'talukaname': fields.many2one('person.taluka','Taluka 
Code',size=32),
        }
person_village()

class person_final(osv.osv):
        _name = 'person.final'
        _defaults = {
                'farmerno': lambda obj, cr, uid, context: 
obj.pool.get('ir.sequence').get(cr, uid, 'person.final'),
                }
        def write(self, cr, user, vals, context=None):
            vals['name'] = vals['state'] + vals['district'] + 
vals['talukaname'] + vals['villagename'] + vals['farmerno']
            return super(person_final,self).create(cr, user, vals, context)

        def create(self, cr, user, vals, context=None):
            vals['name'] = vals['state'] + vals['district'] + 
vals['talukaname'] + vals['villagename'] + vals['farmerno']
            return super(person_final,self).create(cr, user, vals, context)
        
        _columns = {
                'name': fields.char('Farmer Unique 
ID',size=32,select=1,readonly=True),
                'state': fields.many2one('person.state','State 
Code',size=32,required=True),
                'district': fields.many2one('person.district','District 
Code',size=32),
                'talukaname': fields.many2one('person.taluka','Taluka 
Code',size=32),
                'villagename': fields.many2one('person.village','Village 
Code',size=32),
                'farmerno': fields.char('Farmer 
Code',size=32,select=1,readonly=True),
        }
        
person_final()


I imported the module successfully, but while saving, error occurred as follows:

Traceback (most recent call last):
  File "netsvc.pyo", line 235, in dispatch
  File "netsvc.pyo", line 74, in __call__
  File "service\web_services.pyo", line 526, in execute
  File "osv\osv.pyo", line 59, in wrapper
  File "osv\osv.pyo", line 119, in execute
  File "osv\osv.pyo", line 111, in execute_cr
  File "C:\Program Files\OpenERP 
AllInOne\Server\addons\farmer_unique_seq.zip\farmer_unique_seq\farmer_unique_seq.py",
 line 57, in create
  File "C:\Program Files\OpenERP 
AllInOne\Server\addons\farmerunique.zip\farmerunique\farmeruniqueid.py", line 
80, in create
KeyError: 'farmerno'

My Actual requirement is

The system should generate a 16 digit Person Unique ID with codes from State, 
District, Taluk, Village and Person number in the village.

State           :000
District        :000
Taluk/Block     :000
Village         :000
Person Num      :0000 Person number in the village)

Person Unique ID =  State + District + Taluk + Village + Person Number

Here, the Person number should increment based on State, District, Taluk, 
village 
For example:
selected one state(111), in that state - one district(222), in that district - 
one taluk(333), in that taluk - one village(444), in this particular village - 
one Person number should be incremented(like 0001).

If i select same above order i.e village(444), Person number should be 
incremented to 0002.
If i select state(111), district(222), taluk(333), but village(555), then the 
Person number should increment to again 0001 ( because, in different village, 
the Person number should be from starting)

And finally, State code + District code + Taluk code + village code + Person 
number(sequence number) should be appended in the "Person Unique ID"

For example: Person Unique ID = 1112223334440001 (16 digit number)

Please tell where iam doing mistake.

Thank you




-------------------- m2f --------------------

--
http://www.openobject.com/forum/viewtopic.php?p=40788#40788

-------------------- m2f --------------------


_______________________________________________
Tinyerp-users mailing list
http://tiny.be/mailman2/listinfo/tinyerp-users

Reply via email to