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

extraction of field via xml

By
myriam
on 5/31/13, 9:05 AM 1,157 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 !!!!!!!!!!!

1
myriam
On 6/2/13, 1:43 PM
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!

0

patrick

--patrick--
1958
| 5 4 7
Baarn, Netherlands
--patrick--
patrick
On 5/31/13, 6:49 PM

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.

0

Med Said BARA

--Med Said BARA--
2664
| 5 5 7
Algeria
--Med Said BARA--
Med Said BARA
On 6/2/13, 7:46 AM

Try: contract.montant_echeance

i still have the same error :-(

myriam
on 6/2/13, 1:49 PM
0
Vivekrajan
On 5/31/13, 9:21 AM

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

heeelp please!!

myriam
on 6/5/13, 8:54 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: 5/31/13, 9:05 AM
Seen: 1157 times
Last updated: 3/16/15, 8:10 AM