class WizardCustomerPer(osv.TransientModel): _name = 'wiz.customer.performance' _description = 'Generate Report for Customer Performance' _columns = { 'start_date': fields.date('Start Date', required=True), 'end_date': fields.date('End Date', required=True), 'partner_id': fields.many2many('res.partner', string='Customer', required=True), 'journal': fields.many2many('account.journal', string='Bank') } def fetch_record(self, journal_id): self.env.cr.execute("""SELECT aml.partner_id,rp.name,SUM(credit) AS amount FROM account_move_line as aml INNER JOIN res_partner as rp ON aml.partner_id=rp.id where journal_id = %s and partner_id in %s and aml.date between '%s' AND '%s' group by aml.partner_id,rp.name order by rp.name""" %(journal_id,tuple(self.partner_id.ids) if len(self.partner_id.ids)>1 else "("+str(self.partner_id.ids[0])+")",self.start_date,self.end_date)) products = self.env.cr.dictfetchall() return products def get_partner_name(self,partner_id): partner_name = self.env['res.partner'].search(([('id', '=', partner_id)])) return partner_name[0].name # # def get_journal_name(self,journal): # journal_name = self.env['account.journal'].search(([('id', '=', journal)])) # return journal_name[0].name def print_report(self, cr, uid, ids, data, context=None): return { 'type': 'ir.actions.report.xml', 'name': 'oc_mutual_customization.report_customer_recov_template', 'report_name': 'oc_mutual_customization.report_customer_recov_template' }
class WizardReports(osv.TransientModel): _name = 'wiz.report.balances' _description = 'PDF Reports for showing all disconnection,reconnection' _columns = { 'company_id': fields.many2one('res.company', string='Company'), # 'fiscalyear_id': fields.many2one('account.fiscalyear', string='Fiscal Year'), 'start_date': fields.date('Start Date'), 'end_date': fields.date('End Date'), } _defaults = { 'start_date': lambda *a: datetime.now().strftime('%Y-%m-%d'), 'end_date': lambda *a: datetime.now().strftime('%Y-%m-%d'), } def cal_balances(self): self.env.cr.execute( "select cs_category,sum(account_move_line.debit)as debit,sum(account_move_line.credit) as credit from res_partner inner join account_move_line on res_partner.id = account_move_line.partner_id " "where customer = True and res_partner.company_id ='" + str(self.company_id.id) + "'" + "and account_move_line.date >='" + self.start_date + "'" + "and account_move_line.date<='" + str(self.end_date) + "'" "group by cs_category order by cs_category ") result = self.env.cr.dictfetchall() return result def print_report(self, cr, uid, ids, data, context=None): return { 'type': 'ir.actions.report.xml', 'name': 'mutual_reports.wiz_report_balances', 'report_name': 'mutual_reports.wiz_report_balances' }
class report_kas_besar(orm.TransientModel): _name = 'dym.kas.besar' _description = 'Report Kas Besar' _columns = { 'start_date': fields.date('Start Date'), 'end_date': fields.date('End Date'), 'branch_id': fields.many2one('dym.branch', 'Branch'), 'journal_id': fields.many2one( 'account.journal', 'Journal', domain= "[('type','in',['cash']),('branch_id','in',[False,branch_id])]"), } def branch_id_onchange(self, cr, uid, ids, branch_id, context=None): dom = {} val = {} return {'domain': dom, 'value': val} def print_report(self, cr, uid, ids, context=None): if context is None: context = {} data = self.read(cr, uid, ids)[0] journal_id = data['journal_id'] start_date = data['start_date'] end_date = data['end_date'] #start_value_date = data['start_value_date'] #end_value_date = data['end_value_date'] branch_id = data['branch_id'] data.update({ 'branch_id': branch_id, 'journal_id': journal_id, 'start_date': start_date, 'end_date': end_date, #'start_value_date': start_value_date, #'end_value_date': end_value_date, }) if context.get('xls_export'): return { 'type': 'ir.actions.report.xml', 'report_name': 'dym_report_kas_besar_xls', 'datas': data } else: context['landscape'] = True return self.pool['report'].get_action( cr, uid, [], 'dym_kas_besar.report_kas_besar', data=data, context=context) def xls_export(self, cr, uid, ids, context=None): return self.print_report(cr, uid, ids, context)
class prestamos( osv.osv): _name="prestamo.libro" _description = 'prestamos de libros' _columns = { 'name':fields.char('prestamo',required=False), # ID del modelo cliente es decir una relacion many2one al nombre del cliente 'cliente_id': fields.many2one('cliente.libro',string="nombre del cliente", required=True, select=True, help='Tipo de libro', store=True), 'fecha_prestamo': fields.date('Fecha de entrega', required=True), 'devolucion': fields.date('Fecha de devolucion' ,required=True), }
class ProductTemplate(orm.Model): _inherit = 'product.template' _columns = { 'date_start': fields.date("Start date"), 'date_end': fields.date("End Date"), 'period': fields.selection([('week', 'Week'), ('month', 'Month'), ('year', 'Year')], 'Time Period'), 'analysis_type': fields.selection([('average', 'Average'), ('end_of_period', 'End of period')], 'Type of analysis'), 'stock_graphic': fields.binary("Graph") } _defaults = { 'date_start': lambda *a: (datetime.now() - relativedelta(months=6)).strftime('%Y-%m-%d'), 'date_end': lambda *a: datetime.now().strftime('%Y-%m-%d'), 'period': 'month', 'analysis_type': 'average' }
class hr_salary_rule_variable(models.Model): _name = 'hr.salary.rule.variable' _description = 'Variables used on salary rules that change over the years' _columns = { 'salary_rule_id': fields.many2one( 'hr.salary.rule', 'Salary Rule', ondelete='cascade', required=True, ), 'date_from': fields.date( 'Date From', required=True, ), 'date_to': fields.date('Date To', ), 'type': fields.selection([('python', 'Python Code'), ('fixed', 'Fixed Amount')], string='Type'), 'python_code': fields.text('Python Code'), 'fixed_amount': fields.float('Fixed Amount'), }
class wolftrakglobal_report_608(osv.osv): _name = 'wolftrakglobal.report608' _columns = { 'invoices': fields.many2many('account.invoice', domain=[('type', '=', 'out_refund'), ('company_id', '=', 3)], string="Facturas"), 'desde_608': fields.date('Desde:'), 'desde_str': fields.char(compute='_toma_desde'), 'hasta_608': fields.date('Hasta:'), 'hasta_str': fields.char(compute='_toma_hasta'), 'periodo': fields.char(compute='_toma_periodo', readonly=True, string='Periodo'), 'cant_reg': fields.integer('Cantidad de registros') } _defaults = { 'desde_608': lambda *a: time.strftime('%Y-%m-01'), 'hasta_608': lambda *a: str(datetime.now() + relativedelta.relativedelta( months=+1, day=1, days=-1))[:10], } @api.onchange('invoices') def _toma_registro(self): for value in self.invoices: self.cant_reg = len(self.invoices) @api.depends('hasta_608') def _toma_periodo(self): month = str(self.hasta_608[5:7]) year = str(self.hasta_608[:4]) self.periodo = year + month @api.depends('desde_608') def _toma_desde(self): year = str(self.desde_608[:4]) month = str(self.desde_608[5:7]) day = str(self.desde_608[8:10]) self.desde_str = year + month + day @api.depends('hasta_608') def _toma_hasta(self): year = str(self.hasta_608[:4]) month = str(self.hasta_608[5:7]) day = str(self.hasta_608[8:10]) self.hasta_str = year + month + day
class WizardReports(osv.TransientModel): _name = 'wiz.invoices.writeoff' _description = 'PDF Reports for showing all disconnection,reconnection' _columns = { 'date': fields.date('Invoice Date', required=True), 'cheque_no': fields.char('Cheque No', required=True), 'bank_code': fields.selection([ ('FBL', 'FBL'), ('JSBL', 'JSBL'), ], required=True, string='Bank Code'), 'invoice_amount': fields.float('Invoice Amount', required=True), 'received_amount': fields.float('Received Amount', required=True) } def inv_status_changed(self, central, south, north, main): self.env.cr.execute( "UPDATE account_invoice " "SET state='cancel', payment_received=True,courier=True" + ",cheque_no='" + str(self.cheque_no) + "'" + ",comment='Payment has been received against parent invoice therefore user cancelled this invoice' " "FROM res_partner WHERE account_invoice.partner_id = res_partner.id and account_invoice.state='draft' " + "and res_partner.bank_code='" + str(self.bank_code) + "'" + "and account_invoice.invoice_date='" + str(self.date) + "'" + "and account_invoice.amount_total='" + str(self.invoice_amount) + "'" + "and account_invoice.partner_id!='" + str(central) + "'" + "and account_invoice.partner_id != '" + str(south) + "'" + "and account_invoice.partner_id !='" + str(north) + "'" + "and account_invoice.partner_id !=" + str(main)) return True @api.one def inv_status_change_request(self): if self.bank_code == 'FBL': fbl_central = 9464 fbl_south = 9522 fbl_north = 9450 fbl_main = 9572 result = self.inv_status_changed(fbl_central, fbl_south, fbl_north, fbl_main) return result if self.bank_code == 'JSBL': jsbl_central = 11056 jsbl_south = 11057 jsbl_north = 11058 jsbl_main = 3349 result = self.inv_status_changed(jsbl_central, jsbl_south, jsbl_north, jsbl_main) return result raise osv.except_osv("Done........", "Records have been successfully updated")
class WizardDailyReport(osv.TransientModel): _name='wiz.daily.report' _description='daily reporting of customer entries' _columns={ 'date': fields.date('Date',required=True), 'company_id_invoice': fields.many2one('res.company', 'Company ID', required=True), 'journal_id_daily' : fields.many2one('account.journal','Journal ID',required=True) } _defaults = { 'date': lambda *a: datetime.now().strftime('%Y-%m-%d') } def fetch_record(self): state='posted' self.env.cr.execute('select jour_en.name journal_entry,jour_it.ref,part.name partner_name,part.cs_number cs_number,acc_jou.name journal,acc_acc.name account_name,jour_en.date,jour_it.credit,jour_it.debit from public.account_move_line jour_it' +' left join public.account_move jour_en on jour_it.move_id=jour_en.id ' +'left join public.res_partner part on jour_it.partner_id=part.id ' +'left join public.account_journal acc_jou on jour_it.journal_id=acc_jou.id ' +'left join public.account_account acc_acc on jour_it.account_id=acc_acc.id' +' where jour_it.date = '+"'"+self.date +"'"+' and jour_it.company_id='+"'"+str(self.company_id_invoice.id )+"'" +'and jour_it.journal_id='+"'"+str(self.journal_id_daily.id )+"'"+' and jour_en.state='+"'"+state+"'"+' order by jour_en.name asc,jour_it.debit desc') daily_list=self.env.cr.dictfetchall() return daily_list def print_report(self, cr, uid, ids, data, context=None): return { 'type': 'ir.actions.report.xml', 'name': 'invoice_csnumber.report_daily_report', 'report_name': 'invoice_csnumber.report_daily_report' }
class nomor_faktur_pajak(osv.osv): _name = "nomor.faktur.pajak" _description = 'Nomor faktur Pajak' def _nomor_faktur(self, cr, uid, ids, nomorfaktur, arg, context=None): res = {} for nomor in self.browse(cr, uid, ids, context): res[nomor.id] = "%s.%s.%s" % (nomor.nomor_perusahaan, nomor.tahun_penerbit, nomor.nomor_urut) return res _columns = { 'nomor_perusahaan' : fields.char('Nomor Perusahaan', size=3), 'tahun_penerbit': fields.char('Tahun Penerbit', size=2), 'nomor_urut': fields.char('Nomor Urut', size=8), 'name': fields.function(_nomor_faktur, type='char', string="Nomor Faktur", store=True), 'invoice_id': fields.many2one('account.invoice','Invoice No'), 'partner_id' : fields.many2one('res.partner', "Customer"), 'dpp' : fields.float('Untaxed Amount'), 'tax_amount': fields.float("Tax Amount"), 'date_used' : fields.date("Used Date"), 'company_id': fields.many2one('res.company', 'Company'), 'currency_id': fields.many2one('res.currency', 'Currency'), 'type' : fields.selection([('in','Faktur Pajak Masukan'),('out','Faktur Pajak Keluaran')],'Type'), 'status': fields.selection([('1','Used'),('0','Not Used')],'Status'), } _defaults = { 'status': '0', } _sql_constraints = [ ('faktur_unique', 'unique(nomor_perusahaan,tahun_penerbit,nomor_urut)', 'Number Faktur Must Be Unique.'), ]
class WizardInvoiceList(osv.TransientModel): _name = 'wiz.invoice.list' _description = 'General report for invoice listing' _columns = { 'date': fields.date('Start Date', required=True), 'company_id_invoice': fields.many2one('res.company', 'Company ID', required=True) } _defaults = {'date': lambda *a: datetime.now().strftime('%Y-%m-%d')} def fetch_record(self): self.env.cr.execute( 'SELECT res_partner.cs_number,res_partner.name,res_partner.credit_card_no,account_invoice.date_due FROM res_partner INNER JOIN account_invoice ON res_partner.id = account_invoice.partner_id where account_invoice.date_invoice =' + "'" + self.date + "'" + ' and account_invoice.company_id=' + "'" + str(self.company_id_invoice.id) + "'" + ' order by res_partner.cs_number asc') inventory_list = self.env.cr.dictfetchall() return inventory_list def print_report(self, cr, uid, ids, data, context=None): return { 'type': 'ir.actions.report.xml', 'name': 'invoice_csnumber.report_invoice_list', 'report_name': 'invoice_csnumber.report_invoice_list' }
class hr_accrual_job(models.Model): _name = 'hr.policy.line.accrual.job' _description = 'Accrual Policy Line Job Run' _columns = { 'name': fields.date('Date', required=True, readonly=True), 'exec': fields.datetime('Execution Date/Time', required=True, readonly=True), 'policy_line_id': fields.many2one('hr.policy.line.accrual', 'Accrual Policy Line', required=True, readonly=True), 'accrual_line_ids': fields.many2many('hr.accrual.line', 'hr_policy_job_accrual_line_rel', 'job_id', 'accrual_line_id', 'Accrual Lines', readonly=True), 'holiday_ids': fields.many2many('hr.holidays', 'hr_policy_job_holiday_rel', 'job_id', 'holiday_id', 'Leave Allocation Requests', readonly=True), }
def create(self, vals): # Compute the default values for 'gueltig_von' and 'gueltig_bis' if none where provided! if 'gueltig_von' not in vals and 'gueltig_bis' not in vals: # Default values for gueltig_von and gueltig_bis gueltig_von = fields.datetime.now() gueltig_bis = fields.date(2099, 12, 31) # Set to 'approval needed magic date' if bestaetigung_erforderlich is set in the group group_model_field_name = self._group_model_field vals_group_id = vals.get(group_model_field_name, False) if vals_group_id: group_model_name = self._fields.get( group_model_field_name).comodel_name group = self.env[group_model_name].browse([vals_group_id]) if group.bestaetigung_erforderlich: gueltig_von = self._approval_pending_date gueltig_bis = self._approval_pending_date # Add to vals vals['gueltig_von'] = gueltig_von vals['gueltig_bis'] = gueltig_bis # Create the record return super(FRSTGruppeState, self).create(vals)
class report(osv.osv): _name = "graph.report" _auto = False _columns = { 'tanggal' : fields.date('Tanggal', readonly=True), 'ashar' : fields. many2one('mutabaah.ashar', 'Ashar', readonly=True), 'maghrib' : fields.many2one('mutabaah.maghrib', 'Maghrib', readonly=True), 'isya' : fields.many2one('mutabaah.isya', 'Isya', readonly=True), 'tilawah' : fields.many2one('mutabaah.tilawah', 'Tilawah', readonly=True), } def init(self, cr): tools.drop_view_if_exists(cr, 'graph.report') cr.execute(""" CREATE OR REPLACE VIEW graph.report AS ( SELECT m.tanggal, m.ashar, m.maghrib, m.isya, m.tilawah FROM "mutabaah" m ) """ )
class bm_lease_rate(osv.osv): _name = "bm.lease.rate" _description = "Building Management Lease Rate" _columns = { 'lease_trans_id': fields.many2one('bm.lease.transaction', 'Trans ID'), 'start_date': fields.date('Start Date', required=True), 'end_date': fields.date('End Date', required=True), 'rate': fields.float('Rate', required=True), 'rupiah': fields.float('Rupiah', required=True), } _defaults = { 'rate': lambda *a: 0.0, 'rupiah': lambda *a: 0.0, }
class policy_presence(models.Model): _name = 'hr.policy.presence' _columns = { 'name': fields.char('Name', size=128, required=True), 'date': fields.date('Effective Date', required=True), 'work_days_per_month': fields.integer('Working Days/Month', required=True), 'line_ids': fields.one2many('hr.policy.line.presence', 'policy_id', 'Policy Lines'), } _defaults = { 'work_days_per_month': 26, } # Return records with latest date first _order = 'date desc' def get_codes(self, cr, uid, idx, context=None): res = [] [ res.append( (line.code, line.name, line.type, line.rate, line.duration)) for line in self.browse(cr, uid, idx, context=context).line_ids ] return res
class hr_warning(models.Model): _name = 'hr.infraction.warning' _description = 'Employee Warning' _columns = { 'name': fields.char( 'Subject', size=256, ), 'date': fields.date( 'Date Issued', ), 'type': fields.selection( [ ('verbal', 'Verbal'), ('written', 'Written'), ], 'Type', required=True, ), 'action_id': fields.many2one( 'hr.infraction.action', 'Action', ondelete='cascade', readonly=True, ), 'infraction_id': fields.related( 'action_id', 'infraction_id', type='many2one', obj='hr.infraction', string='Infraction', readonly=True, ), 'employee_id': fields.related( 'infraction_id', 'employee_id', type='many2one', obj='hr.employee', string='Employee', readonly=True, ), } _defaults = { 'type': 'written', 'date': time.strftime(DEFAULT_SERVER_DATE_FORMAT), } def unlink(self, cr, uid, ids, context=None): for warning in self.browse(cr, uid, ids, context=context): if (warning.action_id and warning.action_id.infraction_id.state != 'draft'): raise models.except_orm( _('Error'), _('Warnings attached to Infractions not in "Draft" state ' 'may not be removed.') ) return super(hr_warning, self).unlink(cr, uid, ids, context=context)
class hr_employee(models.Model): _name = 'hr.employee' _inherit = 'hr.employee' _columns = { 'is_labour_union': fields.boolean('Labour Union Member', ), 'labour_union_date': fields.date('Date of Membership', ), }
class hr_payslip_worked_days(models.Model): _inherit = 'hr.payslip.worked_days' def _get_total(self, cr, uid, ids, field_name, arg=None, context=None): res = {} for wd in self.browse(cr, uid, ids, context=context): res[wd.id] = wd.number_of_hours \ * wd.hourly_rate * wd.rate / 100 return res _columns = { 'hourly_rate': fields.float('Hourly Rate', help="""\ The employee's standard hourly rate for one hour of work. Example, 25 Euros per hour."""), 'rate': fields.float('Rate (%)', help="""\ The rate by which to multiply the standard hourly rate. Example, an overtime hour could be paid the standard rate multiplied by 150%. """), # When a worked day has a number of hours and an hourly rate, # it is necessary to have a date interval, # because hourly rates are likely to change over the time. 'date_from': fields.date('Date From'), 'date_to': fields.date('Date To'), 'total': fields.function( _get_total, method=True, type="float", string="Total", ), } _defaults = { 'hourly_rate': 0, 'rate': 100, 'date_from': lambda *a: datetime.now().strftime(DEFAULT_SERVER_DATE_FORMAT), 'date_to': lambda *a: datetime.now().strftime(DEFAULT_SERVER_DATE_FORMAT) }
class policy_ot(models.Model): _name = 'hr.policy.ot' _columns = { 'name': fields.char('Name', size=128, required=True), 'date': fields.date('Effective Date', required=True), 'line_ids': fields.one2many( 'hr.policy.line.ot', 'policy_id', 'Policy Lines'), } # Return records with latest date first _order = 'date desc' def get_codes(self, cr, uid, idx, context=None): res = [] [res.append((line.code, line.name, line.type, line.rate)) for line in self.browse(cr, uid, idx, context=context).line_ids] return res def daily_codes(self, cr, uid, idx, context=None): res = [] [res.append((line.code, line.name)) for line in self.browse( cr, uid, idx, context=context).line_ids if line.type == 'daily'] return res def restday_codes(self, cr, uid, idx, context=None): return [ (line.code, line.name) for line in self.browse(cr, uid, idx, context=context).line_ids if line.type == 'weekly' and line.active_after_units == 'day' ] def restday2_codes(self, cr, uid, idx, context=None): res = [] [res.append((line.code, line.name)) for line in self.browse( cr, uid, idx, context=context).line_ids if line.type == 'restday'] return res def weekly_codes(self, cr, uid, idx, context=None): return [ (line.code, line.name) for line in self.browse(cr, uid, idx, context=context).line_ids if line.type == 'weekly' and line.active_after_units == 'min' ] def holiday_codes(self, cr, uid, idx, context=None): return [ (line.code, line.name) for line in self.browse(cr, uid, idx, context=context).line_ids if line.type == 'holiday' ]
class custom_calendar_event(osv.osv): _name = "calendar.event" _inherit = 'calendar.event' @api.depends('x_categ_id','x_partner_id') def _compute_categ_id_char(self): self.x_categ_id_char = self.x_categ_id.name if self.x_categ_id_char and self.x_partner_id.display_name and self.x_partner_id.phone: self.name = self.x_categ_id_char+' : '+self.x_partner_id.display_name+', '+self.x_partner_id.phone elif self.x_categ_id_char and self.x_partner_id.display_name: self.name = self.x_categ_id_char+' : '+self.x_partner_id.display_name elif self.x_partner_id.display_name: self.name = self.x_partner_id.display_name elif self.x_categ_id_char: self.name = self.x_categ_id_char else: _columns = { 'x_domicile': fields.boolean('A domicile'), 'x_partner_id': fields.many2one('res.partner', 'Attendee', default=''), 'x_categ_id': fields.many2one('calendar.event.type', 'Tags'), 'x_categ_id_char': fields.char(compute='_compute_categ_id_char', default=''), 'x_event_is_billed': fields.boolean('is_billed'), 'x_event_is_printed': fields.boolean('is_printed'), # related field res.partner # ------------------------- 'x_event_display_name' : fields.related('x_partner_id', 'display_name', type="char"), 'x_event_name' : fields.related('x_partner_id', 'name', type="char"), 'x_event_phone' : fields.related('x_partner_id', 'phone', type="char", default=''), 'x_event_patient_prenom': fields.related('x_partner_id', 'x_patient_prenom', type="char"), 'x_event_patient_sexe': fields.related('x_partner_id', 'x_patient_sexe', type="selection", selection=SEXE_SELECTION), 'x_event_patient_cafat': fields.related('x_partner_id', 'x_patient_cafat', type="char"), 'x_event_dob': fields.date(related='x_partner_id.dob'), 'x_event_age' : fields.integer(related='x_partner_id.age'), 'x_event_src_avatar' : fields.binary(related='x_partner_id.x_src_avatar'), 'x_event_medecin_traitant': fields.char(related='x_partner_id.x_medecin_traitant'), ########## MEDICAL INFO ??? # 'x_event_groupe_sang': fields.related('x_partner_id', 'x_groupe_sang', type="selection", selection=GRP_SANG_SELECTION), # 'x_event_taille': fields.float(related='x_partner_id.x_taille'), # 'x_event_poids': fields.float(related='x_partner_id.x_poids'), # 'x_event_IMC': fields.float(related='x_partner_id.x_IMC'), ########## # related field calendar_event_type # ------------------------- 'x_event_codeActe': fields.char(related='x_categ_id.x_code_acte', size=8), 'x_event_priceActe': fields.float(related='x_categ_id.x_price_acte', digits=(4,0)), # ------------------------- } _default = { 'x_domicile': False, }
class wage_increment(models.Model): _name = 'hr.contract.wage.increment' _description = 'HR Contract Wage Increment' _columns = { 'effective_date': fields.date( 'Effective Date', required=True, ), 'wage': fields.float('Amount', digits=(16, 2)), 'contract_id': fields.many2one( 'hr.contract', 'Contract', ), } def _get_contract_id(self, cr, uid, context=None): if context is None: context = {} return context.get('active_id', False) _defaults = {'contract_id': _get_contract_id} _rec_name = 'effective_date' def action_wage_increment(self, cr, uid, ids, context=None): hr_obj = self.pool.get('hr.contract') # Copy the contract and adjust start/end dates and wage accordingly. # for wi in self.browse(cr, uid, ids, context=context): data = hr_obj.copy_data(cr, uid, wi.contract_id.id, context=context) data['name'] = data['name'] + \ _(' - Wage Change ') + wi.effective_date data['wage'] = wi.wage data['date_start'] = wi.effective_date c_id = hr_obj.create(cr, uid, data, context=context) if c_id: effective_date = datetime.strptime(wi.effective_date, '%Y-%m-%d').date() date_end = effective_date + relativedelta(days=1) vals = { 'date_end': date_end.stftime('%Y-%m-%d'), } hr_obj.write(cr, uid, wi.contract_id.id, vals, context=context) return {'type': 'ir.actions.act_window_close'}
def button_open_personemailgruppe(self): assert self.ensure_one(), "Please select one partner only!" action = self.env['ir.actions.act_window'].for_xml_id( 'fso_frst_groups', 'frst_personemailgruppe_action') action['domain'] = [('frst_personemail_id.partner_id', '=', self.id)] action['context'] = { 'default_frst_personemail_id': self.main_personemail_id.id, 'default_gueltig_von': fields.datetime.now().strftime(DEFAULT_SERVER_DATE_FORMAT), 'default_gueltig_bis': fields.date(2099, 12, 31).strftime(DEFAULT_SERVER_DATE_FORMAT), } return action
class cliente (osv.osv): _name="cliente.libro" _description = 'clientes' _columns = { 'name': fields.char('nombre', size=65, required=True, readonly=False), 'apellidos': fields.char('apellidos', size=65, required=False, readonly=False), 'fecha_nacimiento': fields.date('fecha_defecto'), 'edad': fields.char('edad') } _defaults = { # valores por defecto en los campos que queramos en este caso la fecha, para que no nos de error 'fecha_nacimiento': datetime.now() } @api.onchange('fecha_nacimiento') # indicamos los campos que van a cambiar def _onchange_edad(self): fecha_ingresada = self.fecha_nacimiento #almacenamos el campo fecha de nacimiento d = fecha_ingresada.split('-') #separamos por guión fecha_a_calcular = datetime.strptime(d[0] + d[1] + d[2],'%Y%m%d').date() #calculo de la fecha total = datetime.now().date() - fecha_a_calcular #resta entre una fecha y otra self.edad = total.days / 365 #devolucion del campo edad formateado como fecha
class policy_absence(models.Model): _name = 'hr.policy.absence' _columns = { 'name': fields.char('Name', size=128, required=True), 'date': fields.date('Effective Date', required=True), 'line_ids': fields.one2many('hr.policy.line.absence', 'policy_id', 'Policy Lines'), } # Return records with latest date first _order = 'date desc' def get_codes(self, cr, uid, idx, context=None): res = [] [ res.append( (line.code, line.name, line.type, line.rate, line.use_awol)) for line in self.browse(cr, uid, idx, context=context).line_ids ] return res def paid_codes(self, cr, uid, idx, context=None): res = [] [ res.append((line.code, line.name)) for line in self.browse(cr, uid, idx, context=context).line_ids if line.type == 'paid' ] return res def unpaid_codes(self, cr, uid, idx, context=None): res = [] [ res.append((line.code, line.name)) for line in self.browse(cr, uid, idx, context=context).line_ids if line.type == 'unpaid' ] return res
class biblioteca_libro(osv.osv): _name = 'biblioteca.libro' _description = 'biblioteca' _columns = { #'libros_id': fields.many2one('tipo.libro', string="tipo de libro", # required=True, select=True, RELACION MUCHOS A UNO # help='Tipo de libro', store=True ), #RELACION MUCHOS A MUCHOS CON LA TABLA TIPO.LIBRO 'tipos_id': fields.many2many('tipo.libro', 'tipo_libro_rel', id1='libro_id', id2='tipo_id', string="tipo de libro"), 'prestamo_id': fields.many2one('prestamo.libro', string="prestamo de libro",required=False, select=True, store=True), 'name':fields.char('nombre', size=64, required=False, readonly=False), 'description': fields.text('Description'), 'date': fields.date('fecha publicacion'), 'autor':fields.char('autor', size=64, required=False, readonly=False), 'cantidad':fields.integer('numero de libros disponibles', required=True, store=True), } _defaults = { 'prestamo_id': "no hay prestamos" } @api.onchange('prestamo_id') # indicamos los campos que van a cambiar def _onchange_edad(self): self.cantidad = self.cantidad -1
class restday(models.TransientModel): _name = 'hr.restday.wizard' _description = 'Schedule Template Change Wizard' _columns = { 'employee_id': fields.many2one( 'hr.employee', 'Employee', required=True, ), 'contract_id': fields.related( 'employee_id', 'contract_id', type='many2one', relation='hr.contract', string='Contract', readonly=True, ), 'st_current_id': fields.many2one( 'hr.schedule.template', 'Current Template', readonly=True, ), 'st_new_id': fields.many2one( 'hr.schedule.template', 'New Template', ), 'permanent': fields.boolean('Make Permanent', ), 'temp_restday': fields.boolean( 'Temporary Rest Day Change', help="If selected, change the rest day to the specified day only " "for the selected schedule.", ), 'dayofweek': fields.selection( [('0', 'Monday'), ('1', 'Tuesday'), ('2', 'Wednesday'), ('3', 'Thursday'), ('4', 'Friday'), ('5', 'Saturday'), ('6', 'Sunday')], 'Rest Day', select=True, ), 'temp_week_start': fields.date('Start of Week', ), 'week_start': fields.date('Start of Week', ), } _defaults = { 'temp_restday': False, } def onchange_employee(self, cr, uid, ids, ee_id, context=None): res = {'value': {'st_current_id': False}} if ee_id: ee = self.pool.get('hr.employee').browse(cr, uid, ee_id, context=None) res['value'][ 'st_current_id'] = ee.contract_id.schedule_template_id.id return res def onchange_week(self, cr, uid, ids, newdate): res = {'value': {'week_start': newdate}} if newdate: d = datetime.strptime(newdate, "%Y-%m-%d") if d.weekday() != 0: res['value']['week_start'] = False return res return res def onchange_temp_week(self, cr, uid, ids, newdate): res = {'value': {'temp_week_start': newdate}} if newdate: d = datetime.strptime(newdate, "%Y-%m-%d") if d.weekday() != 0: res['value']['temp_week_start'] = False return res return res def _create_detail(self, cr, uid, schedule, actual_dayofweek, template_dayofweek, week_start, context=None): # First, see if there's a schedule for the actual dayofweek. # If so, use it. # for worktime in schedule.template_id.worktime_ids: if worktime.dayofweek == actual_dayofweek: template_dayofweek = actual_dayofweek prevutcdtStart = False prevDayofWeek = False user = self.pool.get('res.users').browse(cr, uid, uid, context=context) local_tz = timezone(user.tz) dSchedStart = datetime.strptime(schedule.date_start, OE_DFORMAT).date() dWeekStart = schedule.date_start < week_start and datetime.strptime( week_start, OE_DFORMAT).date() or dSchedStart for worktime in schedule.template_id.worktime_ids: if worktime.dayofweek != template_dayofweek: continue hour, sep, minute = worktime.hour_from.partition(':') toHour, toSep, toMin = worktime.hour_to.partition(':') if len(sep) == 0 or len(toSep) == 0: raise models.except_orm( _('Invalid Time Format'), _('The time should be entered as HH:MM')) # TODO - Someone affected by DST should fix this # dtStart = datetime.strptime( dWeekStart.strftime('%Y-%m-%d') + ' ' + hour + ':' + minute + ':00', '%Y-%m-%d %H:%M:%S') locldtStart = local_tz.localize(dtStart, is_dst=False) utcdtStart = locldtStart.astimezone(utc) if actual_dayofweek != '0': utcdtStart = utcdtStart + \ relativedelta(days=+int(actual_dayofweek)) dDay = utcdtStart.astimezone(local_tz).date() # If this worktime is a continuation (i.e - after lunch) set the # start time based on the difference from the previous record # if prevDayofWeek and prevDayofWeek == actual_dayofweek: prevHour = prevutcdtStart.strftime('%H') prevMin = prevutcdtStart.strftime('%M') curHour = utcdtStart.strftime('%H') curMin = utcdtStart.strftime('%M') delta_seconds = ( datetime.strptime(curHour + ':' + curMin, '%H:%M') - datetime.strptime(prevHour + ':' + prevMin, '%H:%M')).seconds utcdtStart = prevutcdtStart + timedelta(seconds=+delta_seconds) dDay = prevutcdtStart.astimezone(local_tz).date() delta_seconds = ( datetime.strptime(toHour + ':' + toMin, '%H:%M') - datetime.strptime(hour + ':' + minute, '%H:%M')).seconds utcdtEnd = utcdtStart + timedelta(seconds=+delta_seconds) val = { 'name': schedule.name, 'dayofweek': actual_dayofweek, 'day': dDay, 'date_start': utcdtStart.strftime('%Y-%m-%d %H:%M:%S'), 'date_end': utcdtEnd.strftime('%Y-%m-%d %H:%M:%S'), 'schedule_id': schedule.id, } self.pool.get('hr.schedule').write(cr, uid, schedule.id, { 'detail_ids': [(0, 0, val)], }, context=context) prevDayofWeek = worktime.dayofweek prevutcdtStart = utcdtStart def _change_restday(self, cr, uid, employee_id, week_start, dayofweek, context=None): sched_obj = self.pool.get('hr.schedule') sched_detail_obj = self.pool.get('hr.schedule.detail') schedule_ids = sched_obj.search(cr, uid, [('employee_id', '=', employee_id), ('date_start', '<=', week_start), ('date_end', '>=', week_start), ('state', 'not in', ['locked'])], context=context) sched = sched_obj.browse(cr, uid, schedule_ids[0], context=context) dtFirstDay = datetime.strptime(sched.detail_ids[0].date_start, OE_DTFORMAT) date_start = (dtFirstDay.strftime(OE_DFORMAT) < week_start and week_start + ' ' + dtFirstDay.strftime('%H:%M:%S') or dtFirstDay.strftime(OE_DTFORMAT)) dtNextWeek = datetime.strptime(date_start, OE_DTFORMAT) + relativedelta(weeks=+1) # First get the current rest days rest_days = sched_obj.get_rest_days_by_id( cr, uid, sched.id, dtFirstDay.strftime(OE_DFORMAT), context=context) # Next, remove the schedule detail for the new rest day for dtl in sched.detail_ids: if (dtl.date_start < week_start or datetime.strptime( dtl.date_start, OE_DTFORMAT) >= dtNextWeek): continue if dtl.dayofweek == dayofweek: sched_detail_obj.unlink(cr, uid, dtl.id, context=context) # Enter the new rest day(s) # sched_obj = self.pool.get('hr.schedule') nrest_days = [dayofweek] + rest_days[1:] dSchedStart = datetime.strptime(sched.date_start, OE_DFORMAT).date() dWeekStart = sched.date_start < week_start and datetime.strptime( week_start, OE_DFORMAT).date() or dSchedStart if dWeekStart == dSchedStart: sched_obj.add_restdays(cr, uid, sched, 'restday_ids1', rest_days=nrest_days, context=context) elif dWeekStart == dSchedStart + relativedelta(days=+7): sched_obj.add_restdays(cr, uid, sched, 'restday_ids2', rest_days=nrest_days, context=context) elif dWeekStart == dSchedStart + relativedelta(days=+14): sched_obj.add_restdays(cr, uid, sched, 'restday_ids3', rest_days=nrest_days, context=context) elif dWeekStart == dSchedStart + relativedelta(days=+21): sched_obj.add_restdays(cr, uid, sched, 'restday_ids4', rest_days=nrest_days, context=context) elif dWeekStart == dSchedStart + relativedelta(days=+28): sched_obj.add_restdays(cr, uid, sched, 'restday_ids5', rest_days=nrest_days, context=context) # Last, add a schedule detail for the first rest day in the week using # the template for the new (temp) rest day # if len(rest_days) > 0: self._create_detail(cr, uid, sched, str(rest_days[0]), dayofweek, week_start, context=context) def _remove_add_schedule(self, cr, uid, schedule_id, week_start, tpl_id, context=None): """Remove the current schedule and add a new one in its place according to the new template. If the week that the change starts in is not at the beginning of a schedule create two new schedules to accommodate the truncated old one and the partial new one. """ sched_obj = self.pool.get('hr.schedule') sched = sched_obj.browse(cr, uid, schedule_id, context=context) vals2 = False vals1 = { 'name': sched.name, 'employee_id': sched.employee_id.id, 'template_id': tpl_id, 'date_start': sched.date_start, 'date_end': sched.date_end, } if week_start > sched.date_start: dWeekStart = datetime.strptime(week_start, '%Y-%m-%d').date() start_day = dWeekStart.strftime('%Y-%m-%d') vals1['template_id'] = sched.template_id.id vals1['date_end'] = (dWeekStart + relativedelta(days=-1)).strftime('%Y-%m-%d') vals2 = { 'name': (sched.employee_id.name + ': ' + start_day + ' Wk ' + str(dWeekStart.isocalendar()[1])), 'employee_id': sched.employee_id.id, 'template_id': tpl_id, 'date_start': start_day, 'date_end': sched.date_end, } sched_obj.unlink(cr, uid, schedule_id, context=context) _l.warning('vals1: %s', vals1) sched_obj.create(cr, uid, vals1, context=context) if vals2: _l.warning('vals2: %s', vals2) sched_obj.create(cr, uid, vals2, context=context) def _change_by_template(self, cr, uid, employee_id, week_start, new_template_id, doall, context=None): sched_obj = self.pool.get('hr.schedule') schedule_ids = sched_obj.search(cr, uid, [('employee_id', '=', employee_id), ('date_start', '<=', week_start), ('date_end', '>=', week_start), ('state', 'not in', ['locked'])], context=context) # Remove the current schedule and add a new one in its place according # to the new template # if len(schedule_ids) > 0: self._remove_add_schedule(cr, uid, schedule_ids[0], week_start, new_template_id, context=context) # Also, change all subsequent schedules if so directed if doall: ids = sched_obj.search(cr, uid, [('employee_id', '=', employee_id), ('date_start', '>', week_start), ('state', 'not in', ['locked'])], context=context) for i in ids: self._remove_add_schedule(cr, uid, i, week_start, new_template_id, context) def change_restday(self, cr, uid, ids, context=None): data = self.read(cr, uid, ids[0], [], context=context) # Change the rest day for only one schedule if (data.get('temp_restday') and data.get('dayofweek') and data.get('temp_week_start')): self._change_restday(cr, uid, data['employee_id'][0], data['temp_week_start'], data['dayofweek'], context=context) # Change entire week's schedule to the chosen schedule template if (not data.get('temp_restday') and data.get('st_new_id') and data.get('week_start')): if data.get('week_start', False): self._change_by_template(cr, uid, data['employee_id'][0], data['week_start'], data['st_new_id'][0], data.get('permanent', False), context=context) # If this change is permanent modify employee's contract to # reflect the new template # if data.get('permanent', False): self.pool.get('hr.contract').write( cr, uid, data['contract_id'][0], { 'schedule_template_id': data['st_new_id'][0], }, context=context) return { 'name': 'Change Schedule Template', 'view_type': 'form', 'view_mode': 'form', 'res_model': 'hr.restday.wizard', 'type': 'ir.actions.act_window', 'target': 'new', 'context': context }
class wage_increment_run(models.Model): _name = 'hr.contract.wage.increment.run' _description = 'Wage Increment Batches' _inherit = ['ir.needaction_mixin'] _columns = { 'name': fields.char( 'Name', size=64, required=True, readonly=True, states={'draft': [('readonly', False)]}, ), 'effective_date': fields.date( 'Effective Date', required=True, readonly=True, states={'draft': [('readonly', False)]}, ), 'type': fields.selection( [ ('fixed', 'Fixed Amount'), ('percent', 'Percentage'), ('final', 'Final Amount'), ('manual', 'Manual'), ], 'Type', required=True, readonly=True, states={'draft': [('readonly', False)]}, ), 'adjustment_amount': fields.float( 'Adjustment Amount', digits_compute=dp.get_precision('Payroll'), required=True, readonly=True, states={'draft': [('readonly', False)]}, ), 'increment_ids': fields.one2many( 'hr.contract.wage.increment', 'run_id', 'Adjustments', required=False, readonly=False, states={ 'confirm': [('readonly', False)], 'approve': [('readonly', True)], 'decline': [('readonly', True)], }, ), 'state': fields.selection([('draft', 'Draft'), ('confirm', 'Confirmed'), ('approve', 'Approved'), ('decline', 'Declined')], 'State', readonly=True), } _defaults = { 'state': 'draft', } def _needaction_domain_get(self, cr, uid, context=None): users_obj = self.pool.get('res.users') domain = [] if users_obj.has_group(cr, uid, 'hr_security.group_hr_director'): domain = [('state', 'in', ['confirm'])] return domain return False def unlink(self, cr, uid, ids, context=None): if isinstance(ids, (int, long)): ids = [ids] for run in self.browse(cr, uid, ids, context=context): if run.state in ['approve']: raise models.except_orm( _('The adjustment run cannot be deleted!'), _('You may not delete a wage adjustment that is in the ' '%s state.') % run.state) return super(wage_increment_run, self).unlink(cr, uid, ids, context=context) def _state(self, cr, uid, ids, signal, state, context=None): wkf = netsvc.LocalService('workflow') for run in self.browse(cr, uid, ids, context=context): [ wkf.trg_validate(uid, 'hr.contract.wage.increment', incr.id, signal, cr) for incr in run.increment_ids ] self.write(cr, uid, run.id, {'state': state}, context=context) return True def state_confirm(self, cr, uid, ids, context=None): return self._state(cr, uid, ids, 'signal_confirm', 'confirm', context) def state_approve(self, cr, uid, ids, context=None): return self._state(cr, uid, ids, 'signal_approve', 'approve', context) def state_decline(self, cr, uid, ids, context=None): return self._state(cr, uid, ids, 'signal_decline', 'decline', context)
class wage_increment(models.Model): _name = 'hr.contract.wage.increment' _description = 'HR Contract Wage Adjustment' def _calculate_difference(self, cr, uid, ids, field_name, args, context=None): res = dict.fromkeys(ids) for incr in self.browse(cr, uid, ids, context=context): if incr.wage >= incr.contract_id.wage: percent = ((incr.wage / incr.contract_id.wage) - 1.0) * 100.0 else: percent = (1.0 - (incr.wage / incr.contract_id.wage)) * -100.0 res[incr.id] = { 'wage_difference': incr.wage - incr.current_wage, 'wage_difference_percent': percent, } return res def _get_department(self, cr, uid, ids, field_name, arg, context=None): res = dict.fromkeys(ids, False) for incr in self.browse(cr, uid, ids, context=context): res[incr.id] = incr.employee_id.department_id.id, return res _columns = { 'effective_date': fields.date( 'Effective Date', required=True, readonly=True, states={'draft': [('readonly', False)]}, ), 'wage': fields.float( 'New Wage', digits_compute=dp.get_precision('Payroll'), required=True, readonly=True, states={'draft': [('readonly', False)]}, ), 'new_contract_id': fields.many2one( 'hr.contract', 'New Contract', readonly=True, ), 'contract_id': fields.many2one( 'hr.contract', 'Contract', readonly=True, ), 'current_wage': fields.related( 'contract_id', 'wage', type='float', string='Current Wage', store=True, readonly=True, ), 'wage_difference': fields.function( _calculate_difference, type='float', method=True, string='Difference', multi='diff', readonly=True, ), 'wage_difference_percent': fields.function( _calculate_difference, type='float', method=True, string='Percentage', multi='diff', readonly=True, ), 'employee_id': fields.related( 'contract_id', 'employee_id', relation='hr.employee', type='many2one', string='Employee', store=True, readonly=True, ), 'job_id': fields.related( 'contract_id', 'job_id', relation='hr.job', type='many2one', string='Job', store=True, readonly=True, ), 'department_id': fields.related( 'employee_id', 'department_id', relation='hr.department', type='many2one', string='Department', store=True, readonly=True, ), 'state': fields.selection( [('draft', 'Draft'), ('confirm', 'Confirmed'), ('approve', 'Approved'), ('decline', 'Declined')], 'State', readonly=True, ), 'run_id': fields.many2one( 'hr.contract.wage.increment.run', 'Batch Run', readonly=True, ondelete='cascade', ), } def _get_contract_data(self, cr, uid, field_list, context=None): if context is None: context = {} employee_id = self._get_employee(cr, uid, context=context) ee_data = self.pool.get('hr.employee').read(cr, uid, employee_id, ['contract_id'], context=context) contract_id = ee_data.get('contract_id', False)[0] if not contract_id: return False data = self.pool.get('hr.contract').read(cr, uid, contract_id, field_list, context=context) return data def _get_contract_id(self, cr, uid, context=None): data = self._get_contract_data(cr, uid, ['id'], context) return data.get('id', False) def _get_employee(self, cr, uid, context=None): if context is None: context = {} employee_id = context.get('active_id', False) return employee_id def _get_effective_date(self, cr, uid, context=None): contract_id = self._get_contract_id(cr, uid, context=context) if not contract_id: return False contract = self.pool.get('hr.contract').browse(cr, uid, contract_id, context=context) if contract.pps_id: first_day = 1 if contract.pps_id.type == 'monthly': first_day = contract.pps_id.mo_firstday date_format = '%Y-%m-' + first_day dThisMonth = datetime.now().strftime(date_format).strptime( DEFAULT_SERVER_DATE_FORMAT).date() dNextMonth = (datetime.now() + relativedelta(months=+1)).strftime( date_format).strptime(DEFAULT_SERVER_DATE_FORMAT).date() if dThisMonth < datetime.now().date(): return dNextMonth.strftime(DEFAULT_SERVER_DATE_FORMAT) else: return dThisMonth.strftime(DEFAULT_SERVER_DATE_FORMAT) return False _defaults = { 'contract_id': _get_contract_id, 'employee_id': _get_employee, 'effective_date': _get_effective_date, 'state': 'draft', } _rec_name = 'effective_date' def _check_state(self, cr, uid, wage_incr, context=None): wage_incr_ids = self.search( cr, uid, [ ('contract_id', '=', wage_incr.contract_id.id), ('state', 'in', ['draft', 'confirm', 'approved']), ('id', '!=', wage_incr.id), ], context=context) if len(wage_incr_ids) > 0: data = self.pool.get('hr.contract').read(cr, uid, wage_incr.contract_id.id, ['name'], context=context) raise models.except_orm( _('Warning'), _('There is already another wage adjustment in progress for ' 'this contract: %s.') % (data['name'])) contract_obj = self.pool.get('hr.contract') data = contract_obj.read(cr, uid, wage_incr.contract_id.id, ['state', 'date_end'], context=context) if data['state'] in ['draft', 'done']: data = self.pool.get('hr.contract').read(cr, uid, wage_incr.contract_id.id, ['name'], context=context) raise models.except_orm( _('Warning!'), _('The current state of the contract does not permit a wage ' 'change: %s') % (data['name'])) if data.get('date_end', False) and data['date_end'] != '': dContractEnd = datetime.strptime(data['date_end'], DEFAULT_SERVER_DATE_FORMAT) dEffective = datetime.strptime(wage_incr.effective_date, DEFAULT_SERVER_DATE_FORMAT) if dEffective >= dContractEnd: data = self.pool.get('hr.contract').read( cr, uid, wage_incr.contract_id.id, ['name'], context=context) raise models.except_orm( _('Warning!'), _('The contract end date is on or before the effective ' 'date of the adjustment: %s') % (data['name'])) return True def action_wage_increment(self, cr, uid, ids, context=None): hr_obj = self.pool.get('hr.contract') if isinstance(ids, (int, long)): ids = [ids] # Copy the contract and adjust start/end dates and wage accordingly. # for wi in self.browse(cr, uid, ids, context=context): if -0.01 < wi.wage_difference < 0.01: continue self._check_state(cr, uid, wi, context=context) default = { 'wage': wi.wage, 'date_start': wi.effective_date, 'name': False, 'state': False, 'message_ids': False, 'trial_date_start': False, 'trial_date_end': False, } data = hr_obj.copy_data(cr, uid, wi.contract_id.id, default=default, context=context) notes = data.get('notes', False) if not notes: notes = '' notes = notes + \ _('\nSuperceedes (because of wage adjustment) previous ' 'contract: ') + wi.contract_id.name data['notes'] = notes c_id = hr_obj.create(cr, uid, data, context=context) if c_id: if wi.contract_id.notes: notes = wi.contract_id.notes else: notes = '' notes = notes + \ _('\nSuperceeded (for wage adjustment) by contract: ') + \ wi.contract_id.name vals = {'notes': notes, 'date_end': False} wkf = netsvc.LocalService('workflow') # Set the new contract to the appropriate state wkf.trg_validate(uid, 'hr.contract', c_id, 'signal_confirm', cr) # Terminate the current contract (and trigger appropriate state # change) vals['date_end'] = datetime.strptime( wi.effective_date, '%Y-%m-%d').date() + \ relativedelta(days=-1) hr_obj.write(cr, uid, wi.contract_id.id, vals, context=context) wkf.trg_validate(uid, 'hr.contract', wi.contract_id.id, 'signal_done', cr) return def create(self, cr, uid, vals, context=None): contract_id = vals.get('contract_id', False) if not contract_id: if context is not None: contract_id = context.get('active_id') data = self.pool.get('hr.contract').read(cr, uid, contract_id, ['name', 'date_start'], context=context) # Check that the contract start date is before the effective date if vals['effective_date'] <= data['date_start']: raise models.except_orm( _('Error'), _('The effective date of the adjustment must be after the ' 'contract start date. Contract: %s.') % (data['name'])) wage_incr_ids = self.search( cr, uid, [ ('contract_id', '=', contract_id), ('state', 'in', ['draft', 'confirm', 'approved']), ], context=context) if len(wage_incr_ids) > 0: raise models.except_orm( _('Warning'), _('There is already another wage adjustment in progress for ' 'this contract: %s.') % (data['name'])) return super(wage_increment, self).create(cr, uid, vals, context=context) def do_signal_confirm(self, cr, uid, ids, context=None): for wi in self.browse(cr, uid, ids, context=context): self._check_state(cr, uid, wi, context=context) self.write(cr, uid, wi.id, {'state': 'confirm'}, context=context) def do_signal_approve(self, cr, uid, ids, context=None): for i in ids: self.action_wage_increment(cr, uid, [i], context=context) self.write(cr, uid, i, {'state': 'approve'}, context=context) def unlink(self, cr, uid, ids, context=None): for incr in self.browse(cr, uid, ids, context=context): if incr.state in ['approve']: raise models.except_orm( _('The record cannot be deleted!'), _("""\ You may not delete a record that is in a %s state: Employee: %s""") % (incr.state, incr.employee_id.name)) return super(wage_increment, self).unlink(cr, uid, ids, context=context)
class SaleQuickInvoiceConfirmLine(osv.TransientModel): _name = 'sale.quick.invoice.confirm.line' def _get_order_line_info(self, cr, uid, ids, field_name, arg, context=None): down_payment_id = self.pool['ir.values'].get_default( cr, uid, 'sale.config.settings', 'deposit_product_id_setting') res = dict(map(lambda x: (x, 0), ids)) for line in self.browse(cr, uid, ids, context): if line.sale_order_line: sol = line.sale_order_line if field_name == 'product_id': res[line.id] = sol.product_id.name if field_name == 'sequence': res[line.id] = sol.sequence if field_name == 'price_unit': res[line.id] = sol.price_unit if field_name == 'price_total': if line.identification != 'discount': res[line.id] = sol.price_unit if ( sol.product_id.id == down_payment_id) else sol.price_total else: res[line.id] = sol.price_total if field_name == 'product_uom_qty': res[line.id] = sol.product_uom_qty if field_name == 'qty_invoiced' and line.identification == 'commodity': res[line.id] = sol.qty_invoiced if field_name == 'balance': invoice_total = 0.0 for invoice in sol.invoice_lines: if line.identification == 'discount': invoice_total += -invoice.price_subtotal else: invoice_total += invoice.price_subtotal res[line.id] = ( line.price_total - invoice_total ) if line.identification == 'discount' else ( line.price_total - invoice_total) return res _columns = { 'quick_invoice_line': fields.many2one('quick.invoice.confirm', required=True, ondelete='cascade'), 'sale_order_line': fields.many2one('sale.order.line', string='订单行ID', required=True, ondelete='cascade'), 'product_id': fields.function(_get_order_line_info, string='产品', type='char'), 'sequence': fields.function(_get_order_line_info, string='序号', type='integer'), 'price_unit': fields.function(_get_order_line_info, string='单价', type='float'), 'price_total': fields.function(_get_order_line_info, string='小计', type='float'), 'product_uom_qty': fields.function(_get_order_line_info, string='数量', type='float'), 'qty_invoiced': fields.function(_get_order_line_info, string='收款次数', type='float'), 'balance': fields.function(_get_order_line_info, string='余款', type='float'), 'amount': fields.float(string='本次收款'), 'comment': fields.text(string='说明'), 'invoice_number': fields.char(string='收据号'), 'date_invoice': fields.date(string='收款日期'), 'identification': fields.selection([('down_payment', '预付'), ('discount', '优惠'), ('commodity', '产品')], string='类型'), } @api.multi def create_new_invoice(self): imd = self.env['ir.model.data'] action = imd.xmlid_to_object( 'account_expend.act_sale_quick_invoice_confirm') form_view_id = imd.xmlid_to_res_id( 'account_expend.view_sale_quick_invoice_confirm_line_from') result = { 'res_id': self.id, 'name': '收款信息', 'type': action.type, 'view_type': 'form', 'view_model': 'form', 'res_model': action.res_model, 'views': [(form_view_id, 'form')], 'views_id': form_view_id, 'target': 'new', } return result @api.multi def confirm_cancel(self): qid = self.quick_invoice_line.id return self.env['sale.order'].confirm_cancel(qid) # 覆盖sale_make_invoice_advance的发票创建方法 @api.multi def action_invoice_create(self, order_ids, order_line_id, grouped=False, final=False): inv_obj = self.env['account.invoice'] precision = self.env['decimal.precision'].precision_get( 'Product Unit of Measure') orders = self.env['sale.order'].browse(order_ids) invoices = {} for order in orders: group_key = order.id if grouped else (order.partner_invoice_id.id, order.currency_id.id) line = self.env['sale.order.line'].browse(order_line_id) if line: # if float_is_zero(line.qty_to_invoice, precision_digits=precision): # continue if group_key not in invoices: inv_data = order._prepare_invoice() if self.invoice_number: inv_data['invoice_number'] = self.invoice_number if self.date_invoice: inv_data['date_invoice'] = self.date_invoice if self.comment: inv_data['comment'] = self.comment # 如果产品为优惠,那么建立退款收据 if line.product_id.name == u'价格优惠': inv_data['type'] = 'out_refund' invoice = inv_obj.create(inv_data) invoices[group_key] = invoice elif group_key in invoices: vals = {} if order.name not in invoices[group_key].origin.split( ', '): vals['origin'] = invoices[ group_key].origin + ', ' + order.name if order.client_order_ref and order.client_order_ref not in invoices[ group_key].name.split(', '): vals['name'] = invoices[ group_key].name + ', ' + order.client_order_ref invoices[group_key].write(vals) # if not float_is_zero(qty, precision_digits=precision): vals = self._prepare_invoice_line(qty=line.product_uom_qty) vals.update({ 'invoice_id': invoices[group_key].id, 'sale_line_ids': [(6, 0, [line.id])] }) self.env['account.invoice.line'].create(vals) if not invoices: raise UserError(_('There is no invoicable line.')) for invoice in invoices.values(): if not invoice.invoice_line_ids: raise UserError(_('There is no invoicable line.')) if invoice.amount_untaxed < 0: invoice.type = 'out_refund' for line in invoice.invoice_line_ids: line.quantity = line.quantity for line in invoice.invoice_line_ids: line._set_additional_fields(invoice) invoice.compute_taxes() # 调用验证按钮的工作流 if invoice.state not in ('draft', 'proforma', 'proforma2'): pass invoice.signal_workflow('invoice_open') return [inv.id for inv in invoices.values()] @api.multi def _prepare_invoice_line(self, qty): sol = self.sale_order_line product = sol.product_id order_id = sol.order_id res = {} account = product.property_account_income_id or product.categ_id.property_account_income_categ_id if not account: raise UserError(_('Please define income account for this product: "%s" (id:%d) - or for its category: "%s".') % \ (product.name, product.id, product.categ_id.name)) fpos = order_id.fiscal_position_id or order_id.partner_id.property_account_position_id if fpos: account = fpos.map_account(account) # 因为收款改为手写,当出现数量大于1时,一定有计算的必要,变为计算单价的方式 res = { 'name': sol.name, 'sequence': sol.sequence, 'origin': sol.order_id.name, 'account_id': account.id, 'price_unit': self.amount / qty, 'quantity': qty, 'price_subtotal': self.amount, 'discount': sol.discount, 'uom_id': sol.product_uom.id, 'product_id': product.id or False, 'invoice_line_tax_ids': [(6, 0, sol.tax_id.ids)], 'account_analytic_id': sol.order_id.project_id.id, } return res @api.multi def create_invoice(self): if self.identification == 'commodity': self.amount = abs(self.amount) if self.amount <= 0.0: raise ValidationError(u'收款不能小于或等于0.0') if self.identification != 'discount' and self.amount > self.balance: raise ValidationError(u'收款不能大于余款') new_invoices = self.action_invoice_create( [self.sale_order_line.order_id.id], self.sale_order_line.id, grouped=True) invoices = [] for new_invoice in new_invoices: self.env['account.quick.invoice.confirm.line'].create({ 'quick_invoice_line': self.quick_invoice_line.id, 'invoice_id': new_invoice }) return self.confirm_cancel()