[IMP] Improve code and add state on hr.payslip.run object
authorpsi (Open ERP) <psi@tinyerp.co.in>
Wed, 11 May 2011 09:10:09 +0000 (14:40 +0530)
committerpsi (Open ERP) <psi@tinyerp.co.in>
Wed, 11 May 2011 09:10:09 +0000 (14:40 +0530)
bzr revid: psi@tinyerp.co.in-20110511091009-iyu5bloo5ewg5re9

addons/hr_payroll/hr_payroll.py
addons/hr_payroll/hr_payroll_view.xml
addons/hr_payroll/wizard/hr_payroll_payslips_by_employees.py

index d4b23b4..e6bd769 100644 (file)
@@ -208,9 +208,23 @@ class hr_payslip_run(osv.osv):
 
     _name = 'hr.payslip.run'
     _columns = {
-        'name':fields.char('Name', size=256, required=True),
-        'slip_ids':fields.one2many('hr.payslip', 'payslip_run_id', 'Payslips', required=False, readonly=True),
+        'name': fields.char('Name', size=256, readonly=True, states={'draft': [('readonly', False)]}),
+        'slip_ids': fields.one2many('hr.payslip', 'payslip_run_id', 'Payslips', required=False, readonly=True),
+        'state': fields.selection([
+            ('draft', 'Draft'),
+            ('close', 'Close'),
+        ], 'State', select=True, readonly=True)
+    }
+    _defaults = {
+        'state': 'draft',
     }
+
+    def draft_payslip_run(self, cr, uid, ids, context=None):
+        return self.write(cr, uid, ids, {'state': 'draft'}, context=context)
+
+    def close_payslip_run(self, cr, uid, ids, context=None):
+        return self.write(cr, uid, ids, {'state': 'close'}, context=context)
+
 hr_payslip_run()
 
 class hr_payslip(osv.osv):
@@ -236,7 +250,7 @@ class hr_payslip(osv.osv):
         return result
 
     _columns = {
-        'struct_id': fields.many2one('hr.payroll.structure', 'Structure', help='Defines the rules that have to be applied to this payslip, accordingly to the contract chosen. If you let empty the field contract, this field isn\'t mandatory anymore and thus the rules applied will be all the rules set on the structure of all contracts of the employee valid for the chosen period'),
+        'struct_id': fields.many2one('hr.payroll.structure', 'Structure', readonly=True, states={'draft': [('readonly', False)]}, help='Defines the rules that have to be applied to this payslip, accordingly to the contract chosen. If you let empty the field contract, this field isn\'t mandatory anymore and thus the rules applied will be all the rules set on the structure of all contracts of the employee valid for the chosen period'),
         'name': fields.char('Description', size=64, required=False, readonly=True, states={'draft': [('readonly', False)]}),
         'number': fields.char('Reference', size=64, required=False, readonly=True, states={'draft': [('readonly', False)]}),
         'employee_id': fields.many2one('hr.employee', 'Employee', required=True, readonly=True, states={'draft': [('readonly', False)]}),
@@ -257,11 +271,11 @@ class hr_payslip(osv.osv):
             \n* If the salary is paid then state is set to \'Paid Salary\'.\
             \n* The \'Reject\' state is used when user cancel payslip.'),
 #        'line_ids': fields.one2many('hr.payslip.line', 'slip_id', 'Payslip Line', required=False, readonly=True, states={'draft': [('readonly', False)]}),
-        'line_ids': one2many_mod2('hr.payslip.line', 'slip_id', 'Payslip Line',readonly=True, states={'draft':[('readonly',False)]}),
+        'line_ids': one2many_mod2('hr.payslip.line', 'slip_id', 'Payslip Line', readonly=True, states={'draft':[('readonly',False)]}),
         'company_id': fields.many2one('res.company', 'Company', required=False, readonly=True, states={'draft': [('readonly', False)]}),
         'input_line_ids': fields.one2many('hr.payslip.input', 'payslip_id', 'Payslip Inputs', required=False, readonly=True, states={'draft': [('readonly', False)]}),
         'paid': fields.boolean('Made Payment Order ? ', required=False, readonly=True, states={'draft': [('readonly', False)]}),
-        'note': fields.text('Description'),
+        'note': fields.text('Description', readonly=True, states={'draft':[('readonly',False)]}),
         'contract_id': fields.many2one('hr.contract', 'Contract', required=False, readonly=True, states={'draft': [('readonly', False)]}),
         'details_by_salary_head': fields.function(_get_lines_salary_head, method=True, type='one2many', relation='hr.payslip.line', string='Details by Salary Head'),
         'credit_note': fields.boolean('Credit Note', help="Indicates this payslip has a refund of another"),
index 8ff6611..8082418 100644 (file)
                             <separator colspan="4" string="Other Information"/>
                             <group col="5" colspan="2">
                                 <field name="company_id" groups="base.group_multi_company" widget="selection"/>
-                                <field name="payslip_run_id"/>
+                                <field name="payslip_run_id" domain="[('state','=','draft')]"/>
                                 <field name="paid" readonly="1"/>
                             </group>
                             <newline/>
                         <field name="slip_ids" colspan="4" nolabel="1"/>
                     </page>
                 </notebook>
-                <button name="%(action_hr_payslip_by_employees)d" type="action" icon="terp-stock_effects-object-colorize" string="Generate Payslips" />
+                <group col="6" colspan="6">
+                    <field name="state"/>
+                    <button name="%(action_hr_payslip_by_employees)d" type="action" states="draft" icon="gtk-execute" string="Generate Payslips" />
+                    <button name="close_payslip_run" type="object" icon="terp-camera_test" string="Close" states="draft"/>
+                    <button string="Set to Draft" icon="terp-stock_effects-object-colorize" name="draft_payslip_run" type="object" states="close"/>
+                </group>
             </form>
         </field>
     </record>
index 31d2a77..8413bb8 100644 (file)
@@ -52,12 +52,9 @@ class hr_payslip_employees(osv.osv_memory):
                 'struct_id': slip_data['value'].get('struct_id', False),
                 'contract_id': slip_data['value'].get('contract_id', False),
                 'payslip_run_id': context.get('active_id', False),
+                'input_line_ids': [(0, 0, x) for x in slip_data['value'].get('input_line_ids', False)]
             }
-            slip_id = slip_pool.create(cr, uid, res, context=context)
-            for input in slip_data['value']['input_line_ids']:
-                input.update({'payslip_id': slip_id})
-                input_line_pool.create(cr, uid, input, context=context)
-            slip_ids.append(slip_id)
+            slip_ids.append(slip_pool.create(cr, uid, res, context=context))
         slip_pool.compute_sheet(cr, uid, slip_ids, context=context)
         return {'type': 'ir.actions.act_window_close'}