This question has been flagged
4 Replies
3816 Views

i have already created a new category in the module of payroll and of course a new salary rule .. i have a class "avance" related to contract ( the contract have many of "avance"). it's linked like below :

class hr_contract(osv.osv):
_inherit = 'hr.contract'
_name = 'hr.contract'

_columns = {
    'line_av_ids': fields.one2many('hr.avance.pret', 'avance_id', 'Avance et Prêt'),
}

hr_contract()

class hr_avance_pret(osv.osv):
_name = "hr.avance.pret"
_description = "Avance"
 _columns = {
'montant_echeance': fields.function(_compute_montant, method=True, string='Montant d\'échéance'),
'line_contrat': fields.many2one('hr.contract', "contrat"),
}


<record id="hr_payroll.avance" model="hr.salary.rule">
    <field name="name">Remboursement des Prêts</field>
    <field name="code">AVANCE PRET</field>
    <field name="sequence">100000</field>
    <field name="category_id" ref="hr_AVANCE"/>
    <field name="condition_select">none</field>
    <field name="amount_select">code</field>
    <field name="amount_python_compute">**result = contract.line_av_ids.montant_echeance** </field>
    <field name="appears_on_payslip" eval="False"/>
    <field name="note">la valeur des avances et des prêts.</field>
</record>

i have a pyhton error of "amount_pyhton_compute" i need to extract the "montant_echeance" of the calss "avance" I need your help please !!!!!!!!!!!

Avatar
Discard
Author Best Answer
def _compute_montant(self, cr, uid, ids, field_name, arg, context={}):
    result = {}
    for id in ids:
        myself = self.browse(cr, uid, id, context=context)
        res = 0.0
        if myself:
            res = myself.montant_credit / myself.nbre_echeances
            result[id] = res
    return result

This function is in class hr_avance_pret. this function is correct. but my problème that i want to extract the "montant_echance" to use it in my salary rule. in the base module payroll i found you have to do like that to make a new salary rule like this exemple: (that's why i want to use the "amount_python_code")

<record id="hr_rule_secu" model="hr.salary.rule">
    <field name="name">Plafond Securite Sociale</field>
    <field name="code">SECU</field>
    <field name="sequence">1010</field>
    <field name="category_id" ref="SECU"/>
    <field name="appears_on_payslip" eval="False"/>
    <field name="condition_select">none</field>
    <field name="amount_select">code</field>
    <field name="amount_python_compute">result = contract.employee_id.company_id.plafond_secu</field>
</record>

Thank you for your apply!

Avatar
Discard
Best Answer

Try: contract.montant_echeance

Avatar
Discard
Author

i still have the same error :-(

Best Answer

Hi,

I can help you. Can you just tell me where you have defined the method "_compute_montant". Show me the code of the method.

and what is this amount_pyhton_compute? is it a method? if yes, tel me where you have got that

Avatar
Discard
Author

heeelp please!!

Best Answer

The error is caused by the definition of the field 'amount_pyhton_compute' in the XML.

In your case, you probably want to create a function within hr_contract, which will calculate the value of what you want. At the moment I do not have access to my code, otherwise I might show you an example of how to do it.

Avatar
Discard