[ADD] improve code and add demo rule for sales
bzr revid: psi@tinyerp.co.in-20110510111931-4v21peqft66hblpp
This commit is contained in:
@@ -473,7 +473,7 @@ class hr_payslip(osv.osv):
|
||||
res += [attendances] + leaves
|
||||
return res
|
||||
|
||||
def get_input_lines(self, cr, uid, contract_ids, date_from, date_to, context=None):
|
||||
def get_inputs(self, cr, uid, contract_ids, date_from, date_to, context=None):
|
||||
res = []
|
||||
contract_obj = self.pool.get('hr.contract')
|
||||
rule_obj = self.pool.get('hr.salary.rule')
|
||||
@@ -488,7 +488,6 @@ class hr_payslip(osv.osv):
|
||||
for input in rule.input_ids:
|
||||
inputs = {
|
||||
'name': input.name,
|
||||
'sequence': 5,
|
||||
'code': input.code,
|
||||
'contract_id': contract.id,
|
||||
}
|
||||
@@ -510,10 +509,10 @@ class hr_payslip(osv.osv):
|
||||
worked_days = {}
|
||||
for worked_days_line in payslip.worked_days_line_ids:
|
||||
worked_days[worked_days_line.code] = worked_days_line
|
||||
input_lines = {}
|
||||
inputs = {}
|
||||
for input_line in payslip.input_line_ids:
|
||||
input_lines[input_line.code] = input_line
|
||||
localdict = {'heads': {}, 'payslip': payslip, 'worked_days': worked_days, 'input_lines': input_lines}
|
||||
inputs[input_line.code] = input_line
|
||||
localdict = {'heads': {}, 'payslip': payslip, 'worked_days': worked_days, 'inputs': inputs}
|
||||
#get the ids of the structures on the contracts and their parent id as well
|
||||
structure_ids = self.pool.get('hr.contract').get_all_structures(cr, uid, contract_ids, context=context)
|
||||
#get the rules of the structure and thier children
|
||||
@@ -627,7 +626,7 @@ class hr_payslip(osv.osv):
|
||||
|
||||
#computation of the salary input
|
||||
worked_days_line_ids = self.get_worked_day_lines(cr, uid, contract_ids, date_from, date_to, context=context)
|
||||
input_line_ids = self.get_input_lines(cr, uid, contract_ids, date_from, date_to, context=context)
|
||||
input_line_ids = self.get_inputs(cr, uid, contract_ids, date_from, date_to, context=context)
|
||||
res['value'].update({
|
||||
'worked_days_line_ids': worked_days_line_ids,
|
||||
'input_line_ids': input_line_ids,
|
||||
@@ -683,7 +682,7 @@ class hr_payslip_input(osv.osv):
|
||||
'payslip_id': fields.many2one('hr.payslip', 'Pay Slip', required=True),
|
||||
'sequence': fields.integer('Sequence', required=True,),
|
||||
'code': fields.char('Code', size=52, required=True, help="The code that can be used in the salary rules"),
|
||||
'quantity': fields.float('Quantity'),
|
||||
'quantity': fields.float('Quantity', help="It is used in computation. For e.g. A rule for sales having 1% commission of basic salary for per product can defined in expression like result = inputs['S-ASUS']['qunatity']*contract.wage*0.01."),
|
||||
'contract_id': fields.many2one('hr.contract', 'Contract', required=True, help="The contract for which applied this input"),
|
||||
}
|
||||
_order = 'payslip_id, sequence'
|
||||
@@ -744,6 +743,7 @@ class hr_salary_rule(osv.osv):
|
||||
# rules: rules code (previously computed)
|
||||
# heads: dictionary containing the computed heads (sum of amount of all rules belonging to that head). Keys are the head codes.
|
||||
# worked_days: dictionary containing the computed worked days. Keys are the worked days codes.
|
||||
# inputs: dictionary containing the computed inputs. Keys are the inputs codes.
|
||||
|
||||
# Note: returned value have to be set in the variable 'result'
|
||||
|
||||
@@ -758,6 +758,7 @@ result = contract.wage * 0.10''',
|
||||
# rules: rules code (previously computed)
|
||||
# heads: dictionary containing the computed heads (sum of amount of all rules belonging to that head). Keys are the head codes.
|
||||
# worked_days: dictionary containing the computed worked days. Keys are the worked days codes.
|
||||
# inputs: dictionary containing the computed inputs. Keys are the inputs codes.
|
||||
|
||||
# Note: returned value have to be set in the variable 'result'
|
||||
|
||||
|
||||
@@ -60,6 +60,30 @@
|
||||
<field name="name">Meal Voucher</field>
|
||||
<field name="sequence" eval="16"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_salary_rule_sales_commission" model="hr.salary.rule">
|
||||
<field name="amount_select">code</field>
|
||||
<field name="code">SALE</field>
|
||||
<field name="category_id" ref="hr_payroll.ALW"/>
|
||||
<field name="name">Get 1% of sales</field>
|
||||
<field name="sequence" eval="17"/>
|
||||
<field name="amount_python_compute">result = (inputs['S-ASUS']['quantity'] + inputs['S-CHINA']['quantity']) * contract.wage * 0.01</field>
|
||||
</record>
|
||||
|
||||
<!-- Rule Inputs -->
|
||||
|
||||
<record id="hr_rule_input_sale_a" model="hr.rule.input">
|
||||
<field name="code">S-ASUS</field>
|
||||
<field name="name">Sale to ASUStek</field>
|
||||
<field name="input_id" ref="hr_salary_rule_sales_commission"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_rule_input_sale_b" model="hr.rule.input">
|
||||
<field name="code">S-CHINA</field>
|
||||
<field name="name">Sale to China Export</field>
|
||||
<field name="input_id" ref="hr_salary_rule_sales_commission"/>
|
||||
</record>
|
||||
|
||||
<!-- Salary Structure -->
|
||||
|
||||
<record id="structure_001" model="hr.payroll.structure">
|
||||
|
||||
@@ -272,7 +272,7 @@
|
||||
</page>
|
||||
|
||||
<page string="Worked Days">
|
||||
<field name="worked_days_line_ids" colspan="4" nolabel="1" mode="tree">
|
||||
<field name="worked_days_line_ids" colspan="4" nolabel="1">
|
||||
<tree string="Worked Days" editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
@@ -281,8 +281,19 @@
|
||||
<field name="contract_id" groups="base.group_extended"/>
|
||||
<field name="sequence" invisible="True"/>
|
||||
</tree>
|
||||
<form string="Worked Day">
|
||||
<group>
|
||||
<field name="name" select="1"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="payslip_id"/>
|
||||
<field name="sequence" groups="base.group_extended"/>
|
||||
<field name="number_of_days"/>
|
||||
<field name="number_of_hours"/>
|
||||
<field name="contract_id" groups="base.group_extended"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
<field name="input_line_ids" colspan="4" nolabel="1" mode="tree">
|
||||
<field name="input_line_ids" colspan="4" nolabel="1">
|
||||
<tree string="Input Data" editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
@@ -290,6 +301,16 @@
|
||||
<field name="contract_id" groups="base.group_extended"/>
|
||||
<field name="sequence" invisible="True"/>
|
||||
</tree>
|
||||
<form string="Payslip Line">
|
||||
<group>
|
||||
<field name="name" select="1"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="payslip_id"/>
|
||||
<field name="sequence" groups="base.group_extended"/>
|
||||
<field name="quantity"/>
|
||||
<field name="contract_id" groups="base.group_extended"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</page>
|
||||
|
||||
@@ -499,7 +520,7 @@
|
||||
|
||||
<!-- Salary Rules -->
|
||||
|
||||
<record id="hr_salary_rule_tree" model="ir.ui.view">
|
||||
<record id="hr_salary_rule_tree" model="ir.ui.view">
|
||||
<field name="name">hr.salary.rule.tree</field>
|
||||
<field name="model">hr.salary.rule</field>
|
||||
<field name="type">tree</field>
|
||||
@@ -513,94 +534,112 @@
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="hr_salary_rule_form" model="ir.ui.view">
|
||||
<field name="name">hr.salary.rule.form</field>
|
||||
<record id="hr_salary_rule_form" model="ir.ui.view">
|
||||
<field name="name">hr.salary.rule.form</field>
|
||||
<field name="model">hr.salary.rule</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Salary Rules">
|
||||
<group col="6" colspan="6">
|
||||
<field name="name"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="category_id"/>
|
||||
<field name="sequence" />
|
||||
<field name="active"/>
|
||||
<field name="appears_on_payslip" attrs="{'readonly':[('company_contribution','=', True)]}" />
|
||||
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<notebook colspan="6">
|
||||
<page string="General">
|
||||
<group col="4" colspan="6">
|
||||
<separator colspan="4" string="Conditions"/>
|
||||
<field name="condition_select"/><newline/>
|
||||
<field name="condition_python" attrs="{'invisible':[('condition_select','<>','python')], 'required': [('condition_select','=','python')]}" colspan="4"/> <newline/>
|
||||
<field name="condition_range" attrs="{'invisible':[('condition_select','<>','range')], 'required':[('condition_select','=','range')]}"/><newline/>
|
||||
<field name="condition_range_min" colspan="2" attrs="{'invisible':[('condition_select','<>','range')], 'required':[('condition_select','=','range')]}"/>
|
||||
<field name="condition_range_max" colspan="2" attrs="{'invisible':[('condition_select','<>','range')], 'required':[('condition_select','=','range')]}"/>
|
||||
<separator colspan="4" string="Computation"/>
|
||||
<field name="amount_select"/>
|
||||
<field name="quantity" attrs="{'invisible':[('amount_select','=','code')], 'required':[('amount_select','!=','code')]}"/><newline/>
|
||||
<field name="amount_fix" attrs="{'invisible':[('amount_select','<>','fix')], 'required':[('amount_select','=','fix')]}"/>
|
||||
<field colspan="4" name="amount_python_compute" attrs="{'invisible':[('amount_select','<>','code')], 'required':[('amount_select','=','code')]}"/>
|
||||
<field name="amount_percentage_base" attrs="{'invisible':[('amount_select','<>','percentage')], 'required': [('amount_select','=','percentage')]}"/>
|
||||
<field name="amount_percentage" attrs="{'invisible':[('amount_select','<>','percentage')], 'required':[('amount_select','=','percentage')]}"/>
|
||||
<separator colspan="4" string="Company contribution"/>
|
||||
<field name="register_id"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Child Rules">
|
||||
<field name="parent_rule_id"/>
|
||||
<separator colspan="4" string="Children definition"/>
|
||||
<field colspan="4" name="child_ids" nolabel="1"/>
|
||||
</page>
|
||||
<page string="Inputs">
|
||||
<field name="input_ids" colspan="4" nolabel="1" mode="tree, form">
|
||||
<tree string="Input Data" editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
<page string="Description">
|
||||
<field name="note" colspan="4" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_hr_rule_filter" model="ir.ui.view">
|
||||
<field name="name">hr.salary.rule.select</field>
|
||||
<field name="model">hr.salary.rule</field>
|
||||
<field name="type">form</field>
|
||||
<field name="type">search</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Salary Rules">
|
||||
<group col="6" colspan="6">
|
||||
<field name="name"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="category_id"/>
|
||||
<field name="sequence" />
|
||||
<field name="active"/>
|
||||
<field name="appears_on_payslip" attrs="{'readonly':[('company_contribution','=', True)]}" />
|
||||
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
<notebook colspan="6">
|
||||
<page string="General">
|
||||
<group col="4" colspan="6">
|
||||
<separator colspan="4" string="Conditions"/>
|
||||
<field name="condition_select"/><newline/>
|
||||
<field name="condition_python" attrs="{'invisible':[('condition_select','<>','python')], 'required': [('condition_select','=','python')]}" colspan="4"/> <newline/>
|
||||
<field name="condition_range" attrs="{'invisible':[('condition_select','<>','range')], 'required':[('condition_select','=','range')]}"/><newline/>
|
||||
<field name="condition_range_min" colspan="2" attrs="{'invisible':[('condition_select','<>','range')], 'required':[('condition_select','=','range')]}"/>
|
||||
<field name="condition_range_max" colspan="2" attrs="{'invisible':[('condition_select','<>','range')], 'required':[('condition_select','=','range')]}"/>
|
||||
<separator colspan="4" string="Computation"/>
|
||||
<field name="amount_select"/>
|
||||
<field name="quantity" attrs="{'invisible':[('amount_select','=','code')], 'required':[('amount_select','!=','code')]}"/><newline/>
|
||||
<field name="amount_fix" attrs="{'invisible':[('amount_select','<>','fix')], 'required':[('amount_select','=','fix')]}"/>
|
||||
<field colspan="4" name="amount_python_compute" attrs="{'invisible':[('amount_select','<>','code')], 'required':[('amount_select','=','code')]}"/>
|
||||
<field name="amount_percentage_base" attrs="{'invisible':[('amount_select','<>','percentage')], 'required': [('amount_select','=','percentage')]}"/>
|
||||
<field name="amount_percentage" attrs="{'invisible':[('amount_select','<>','percentage')], 'required':[('amount_select','=','percentage')]}"/>
|
||||
<separator colspan="4" string="Company contribution"/>
|
||||
<field name="register_id"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Child Rules">
|
||||
<field name="parent_rule_id"/>
|
||||
<separator colspan="4" string="Children definition"/>
|
||||
<field colspan="4" name="child_ids" nolabel="1"/>
|
||||
</page>
|
||||
<page string="Inputs">
|
||||
<field name="input_ids" colspan="4" nolabel="1" mode="tree">
|
||||
<tree string="Input Data" editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
<page string="Description">
|
||||
<field name="note" colspan="4" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
<search string="Search Salary Rule">
|
||||
<group col="8" colspan="4">
|
||||
<field name="name"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="category_id"/>
|
||||
<field name="condition_range_min"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<group col="8" colspan="4" expand="0" string="Group By...">
|
||||
<filter string="Head" icon="terp-folder-yellow" name="head" context="{'group_by':'category_id'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
</record>
|
||||
|
||||
<record id="view_hr_rule_filter" model="ir.ui.view">
|
||||
<field name="name">hr.salary.rule.select</field>
|
||||
<field name="model">hr.salary.rule</field>
|
||||
<field name="type">search</field>
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Salary Rule">
|
||||
<group col="8" colspan="4">
|
||||
<field name="name"/>
|
||||
<field name="code" select="1"/>
|
||||
<field name="category_id"/>
|
||||
<field name="condition_range_min"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<group col="8" colspan="4" expand="0" string="Group By...">
|
||||
<filter string="Head" icon="terp-folder-yellow" name="head" context="{'group_by':'category_id'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
<record id="action_salary_rule_form" model="ir.actions.act_window">
|
||||
<field name="name">Salary Rules</field>
|
||||
<field name="res_model">hr.salary.rule</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_id" ref="hr_salary_rule_tree"/>
|
||||
<field name="domain">[('parent_rule_id','=',False)]</field>
|
||||
<field name="search_view_id" ref="view_hr_rule_filter"/>
|
||||
</record>
|
||||
|
||||
<record id="action_salary_rule_form" model="ir.actions.act_window">
|
||||
<field name="name">Salary Rules</field>
|
||||
<field name="res_model">hr.salary.rule</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_id" ref="hr_salary_rule_tree"/>
|
||||
<field name="domain">[('parent_rule_id','=',False)]</field>
|
||||
<field name="search_view_id" ref="view_hr_rule_filter"/>
|
||||
</record>
|
||||
<menuitem id="menu_action_hr_salary_rule_form" action="action_salary_rule_form" parent="payroll_configure" sequence="12"/>
|
||||
|
||||
<menuitem id="menu_action_hr_salary_rule_form" action="action_salary_rule_form" parent="payroll_configure" sequence="12"/>
|
||||
<act_window domain="[('slip_id', '=', active_id)]" id="act_payslip_lines" name="Payslip Lines" res_model="hr.payslip.line" src_model="hr.payslip"/>
|
||||
|
||||
<act_window domain="[('slip_id', '=', active_id)]" id="act_payslip_lines" name="Payslip Lines" res_model="hr.payslip.line" src_model="hr.payslip"/>
|
||||
<record id="hr_contribution_register_form" model="ir.ui.view">
|
||||
<field name="name">hr.contribution.register.form</field>
|
||||
<field name="model">hr.contribution.register</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Contribution">
|
||||
<field name="name" select="1"/>
|
||||
<field name="company_id" select="1" groups="base.group_multi_company" widget="selection"/>
|
||||
<notebook colspan="4">
|
||||
<page string="Description">
|
||||
<separator colspan="4" string="Description"/>
|
||||
<field name="note" colspan="4" nolabel="1"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -11,3 +11,4 @@
|
||||
"access_hr_payslip_worked_days ","hr.payslip.worked_days","model_hr_payslip_worked_days","base.group_hr_manager",1,1,1,1
|
||||
"access_hr_salary_rule","hr.salary.rule","model_hr_salary_rule","base.group_hr_manager",1,1,1,1
|
||||
"access_hr_payslip_input","hr.payslip.input","model_hr_payslip_input","base.group_hr_manager",1,1,1,1
|
||||
"access_hr_rule_input","hr.rule.input","model_hr_rule_input","base.group_hr_manager",1,1,1,1
|
||||
|
||||
|
Reference in New Issue
Block a user