Hi Cyril Gaspard,
Thanks to you for answer.
Now, I have this:
prepare_adv()
_______________________________________________________________________
| Ref: ______________ Period: _________ - ___________ |
| _button_here |
|............................................................................................................................|
| ________________________________________________________________ |
| | id | employee | wage_of_contract | compute_40%_of_wage | <---|---- this is my adv()
| |-----------|-------------------------|--------------------------------|----------------------------------------| |
adv.id and adv.employee have in hr_employee, and adv.wage_of_contract have in hr_contract, now, adv.compute_40%_of_wage is automatic compute from adv.wage_of_contract.
I need create this every month but one time, with all employee available. I solved the problem to save datas in adv() and can see this in prepare_adv() but have other problem :)
The problem is the next: when is only one row fine, save and can see perfect; but if it is more than one row show the next error:
Expected singleton: hr.py.advances(104, 105, 103)
Save the data in adv() but show the error mentioned.
I have understood that need create new rows for news records.
This is my code of function from button (this are in prepare_adv()):
def on_click(self, cr, uid, ids, context=None):
res = {}
for adv in self.browse(cr,uid,ids):
cr.execute('''SELECT hr_employee.id, id_inter, wage FROM hr_employee, hr_contract WHERE hr_employee.id=employee_id''')
temp = cr.fetchall()
per = time.strftime('%m/%Y')
for record in temp:
datas = {'advances_id':adv.id,'period_id':per,'id_intern':record[1],'employee_name':record[0],'wage_base':record[2]}
crea = self.pool.get('hr.py.advances').create(cr,uid,datas,context=context)
self.pool.get('hr.py.advances').write(cr,uid,crea,datas,context=context)
return True
This is my adv() class:
class adv(models.Model):
_name = 'adv'
advances_id = fields.Many2one('prepare.adv')
period_id = fields.Char()
id_intern = fields.Integer(string='Cod.')
employee_name = fields.Many2one('hr.employee', string='Funcionario')
wage_base = fields.Float(string='Salario')
advances_40 = fields.Integer(compute='_compute_wage_advance', string='40% Adelanto Quinc.')
@api.depends('wage_base')
def _compute_wage_advance(self):
self.advances_40 = self.wage_base * 0.40
This id my prepare_adv() class:
class prepare_adv(models.Model):
_name = 'prepare.adv'
state = fields.Selection([('draft','Borrador'),('done','Aprobado')], default='draft', string='Status', select=True, readonly=True, copy=False)
referenc = fields.Char(string='Referencia',default='Anticipo - ' + time.strftime('%m/%Y'))
date_from = fields.Datetime(string='Periodo', default=lambda *a: time.strftime('%Y-%m-01'), required=True, readonly=True, states={'draft': [('readonly', False)]})
date_to = fields.Datetime(string='-', default=lambda *a: str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10], required=True, readonly=True, states={'draft': [('readonly', False)]})
per_id = fields.Char(string='per', default= time.strftime('%m/%Y'))
advancs = fields.One2many('adv','advances_id')
This is the view of prepare_adv():
<div class="oe_title">
<label for="referenc" class="oe_edit_only"/>
<h1>
<field name="referenc"/>
</h1>
</div>
<div class="oe_right">
<label for="date_from" class="oe_edit_only"/><field name="date_from" class="oe_inline"/><label for="date_to">-</label><field name="date_to" class="oe_inline"/>
</div>
<group>
<button string="Cargar" name="charge_employee" states="draft" type="object" class="oe_highlight"/>
</group>
<notebook>
<page>
<field name="advancs" nolabel="1"/>
</page>
</notebook>
How create news row for view all amount of employee (around of 72 employee)?
Some can help me please...