Пример #1
0
    def limpiar_registros(self):  #Atributos comentados no pueden ser nulos

        self.fecha_pago = False  #Con el false indicamos que queden vacios
        self.fecha_p = time.strftime("%Y-%m-%d")
        self.fecha_r = False
        self.precio = 0
        self.descripcion = ""
Пример #2
0
 def limpiar_registros(self):  #Atributos comentados no pueden ser nulos
     #self.t_pedido = ""
     self.nombre_p = ""
     self.cantidad = 0
     self.coste = 0
     self.fecha_c = time.strftime("%Y-%m-%d")
     self.descripcion = ""
Пример #3
0
    def limpiar_registros(self):  #Atributos comentados no pueden ser nulos

        self.fecha_pago = None
        self.fecha_p = time.strftime("%Y-%m-%d")
        self.fecha_r = None
        self.precio = 0
        self.descripcion = ""
Пример #4
0
 def _get_default_name(self):
     cr = self.env.cr
     cr.execute(
         'select "id" from "minutas_xmarts" order by "id" desc limit 1')
     id_returned = cr.fetchone()
     if id_returned == None:
         id_returned = (0, )
     return "MINUTA{}-{}".format(time.strftime("%x"), max(id_returned) + 1)
Пример #5
0
class Paciente(models.Model):
    _name = 'gestion_clinica.paciente'
    _description = 'Pacientes'
    _rec_name = 'nif'

    nombre = fields.Char(
        string="Nombre",
        help='Nombre del paciente',
        size=20,
        required=True,
    )
    apellidos = fields.Char(string="Apellidos",
                            help='Apellidos del paciente',
                            size=50,
                            required=True)
    nif = fields.Char(string='NIF',
                      help='Documento de identificacion del paciente',
                      required=True)
    fechaNacimiento = fields.Date(
        string='Fecha de nacimiento',
        help='Día, mes y año de nacimiento del paciente',
        default=time.strftime('1900-01-01'),
        required=True)
    genero = fields.Selection([('femenino', 'Femenino'),
                               ('masculino', 'Masculino')],
                              string='Género',
                              required=True)
    telefono = fields.Char(string='Teléfono',
                           help='Número de teléfono del paciente')
    email = fields.Char(string='Email',
                        help='Correo electrónico del paciente',
                        required=True)
    poblacion = fields.Char(string='Población', help='Lugar de residencia')
    donante = fields.Boolean(string='Donante',
                             help='Donante de ovulos o s***n')
    doctor_id = fields.Many2one('res.users', string='Doctor', required=True)
    patologia_ids = fields.One2many('gestion_clinica.patologia',
                                    'paciente_id',
                                    string='Patologia')
    visita_ids = fields.One2many('gestion_clinica.visita',
                                 'paciente_id',
                                 string='Visita')
    dosis_ids = fields.One2many('gestion_clinica.dosis',
                                'paciente_id',
                                string='Dosis')

    @api.one
    @api.constrains('email')
    def _check_function(self):
        if (("@" not in self.email) or ("." not in self.email)):
            raise exceptions.ValidationError("El campo email no es válido.")
Пример #6
0
    def action_move_create(self):
        """Queda pendiente revisar el punto referente al periodo, porque en el 11 hay un tema con respecto a esto"""
        inv_obj = self.env['account.move']
        ctx = dict(self._context,
                   muni_wh=True,
                   company_id=self.env.user.company_id.id)
        for ret in self.with_context(ctx):
            #Busca si ya hay retenciones para esta factura
            for line in self.munici_line_ids:
                if line.move_id or line.invoice_id.wh_local:
                    raise exceptions.except_orm(
                        _('Factura a retener!'),
                        _("¡Debe omitir la siguiente factura") %
                        (line.invoice_id.name, ))

            acc_id = self.account_id
            if not self.date_ret:
                self.write({'date_ret': time.strftime('%Y-%m-%d')})
                ret = self.browse(ret.id)

            journal_id = ret.journal_id.id

            if ret.munici_line_ids:
                for line in ret.munici_line_ids:
                    writeoff_account_id = False
                    writeoff_journal_id = False
                    amount = line.amount
                    if ret.code and ret.code != False:
                        name = 'COMP. RET. MUN ' + ret.code
                    else:
                        raise exceptions.except_orm(
                            _("No existe un Secuencia creada para la Retencion Municipal"
                              ),
                            _("Por favor cree una secuencia para la Retencion Municipal, en los Ajustes, para poder continuar"
                              ))
                    self.with_context({'wh_county': 'wh_county'})
                    ret_move = line.invoice_id.ret_and_reconcile(
                        amount, acc_id, journal_id, writeoff_account_id,
                        writeoff_journal_id, ret.date_ret, name, line,
                        'wh_muni')
                    # make the retencion line point to that move
                    ret_move.action_post()
                    rl = {
                        'move_id': ret_move.id,
                    }
                    lines = [(1, line.id, rl)]
                    self.write({'munici_line_ids': lines})
                    line.invoice_id.write({'wh_muni_id': ret.id})
        return True
Пример #7
0
    def action_move_create(self):
        """Queda pendiente revisar el punto referente al periodo, porque en el 11 hay un tema con respecto a esto"""
        inv_obj = self.env['account.invoice']
        ctx = dict(self._context, muni_wh=True,
                   company_id=self.env.user.company_id.id)
        for ret in self.with_context(ctx):
            #Busca si ya hay retenciones para esta factura
            for line in self.munici_line_ids:
                if line.move_id or line.invoice_id.wh_local:
                    raise exceptions.except_orm(_('Invoice already withhold !'), _(
                        "You must omit the follow invoice '%s' !") % (line.invoice_id.name,))

            acc_id = self.account_id.id
            if not self.date_ret:
                self.write({'date_ret':time.strftime('%Y-%m-%d')})
                ret = self.browse(ret.id)

            #period_id = ret.period_id and ret.period_id.id or False
            journal_id = ret.journal_id.id
            #if not period_id:
            #    period_ids = self.env['account.period'].search(self.uid, [
            #        ('date_start', '<=', ret.date_ret or time.strftime('%Y-%m-%d')),
            #        ('date_stop', '>=', ret.date_ret or time.strftime('%Y-%m-%d'))])
            #    if len(period_ids):
            #        period_id = period_ids[0]
            #    else:
            #]        raise exceptions.except_orm(
            #            _('Warning !'),
            #            _("There was not found a fiscal period for this date:"
            #              " '%s' please check.!") % (ret.date_ret or time.strftime('%Y-%m-%d')))
            if ret.munici_line_ids:
                for line in ret.munici_line_ids:
                    writeoff_account_id = False
                    writeoff_journal_id = False
                    amount = line.amount
                    name = 'COMP. RET. MUN ' + ret.number
                    self.with_context({'wh_county':'wh_county'})
                    ret_move = inv_obj.ret_and_reconcile(amount, acc_id, journal_id,
                                        writeoff_account_id, writeoff_journal_id,
                                        ret.date_ret, name, line, None,'wh_county')
                    # make the retencion line point to that move
                    rl = {'move_id': ret_move.id,}
                    lines = [(1, line.id, rl)]
                    self.write({'munici_line_ids': lines})
                    inv_obj.write({'wh_muni_id': ret.id})
        return True
Пример #8
0
 def fecha_actual(self):  #No le doy uso
     self.fecha = time.strftime("%Y-%m-%d")
Пример #9
0
 def fecha_actual(self):
     self.fecha = time.strftime("%Y-%m-%d")
Пример #10
0
class hr_bonus_month(models.Model):
    _name = 'hr.bonus.month'

    name = fields.Char(string='Bonus', required=True)
    date = fields.Date(string='Date', default=time.strftime('%Y-%m-01'))

    bonus_ids = fields.One2many('hr.bonus.line',
                                'bonus_id',
                                string='Bonus Month')
    state = fields.Selection(
        [('draft', 'Draft'), ('confirm', 'Confirmed'), ('done', 'Done'),
         ('refuse', 'Refused'), ('auditor', 'Auditor')],
        string="State",
        default='draft',
        track_visibility='onchange',
        copy=False,
    )

    journal_id = fields.Many2one('account.journal', string="Journal")
    account_id = fields.Many2one('account.account', string="Credit Account")
    move_id = fields.Many2one('account.move',
                              string="Journal Entry",
                              readonly=True)
    finance_request = fields.Boolean('Finance Request')

    @api.one
    def bonus_auditor(self):
        for x in self:
            x.state = 'auditor'

#
# @api.depends('date_from', 'date_to')
# def compute_bonus_month(self):
#     for x in self:
#         sale_obj = x.env['sale.person.bonus']
#         bonus_line_obj = x.env['hr.bonus.line']
#         employee_obj = x.env['hr.employee'].search([])
#         x.bonus_ids.unlink()
#         for employee in employee_obj:
#             employee_id = employee.id
#             rec = sale_obj.search(
#                 [('date', '>=', x.date_from), ('date', '<=', x.date_to),('employee_id','=',employee_id)
#                ], order='employee_id')
#             request_amount = 0.0
#             for sales in rec:
#                 request_amount += sales.request_amount
#             if request_amount != 0.0 :
#                 vals = {
#                     'employee_id': employee_id,
#                     'amount': request_amount,
#                     'date_bouns': sales.date,
#                     'invoice_id': sales.invoice_id.id,
#                     'account_id':sales.exp_account.id,
#                     'bonus_id': x.id,
#                                          }
#                 bonus_line_obj.create(vals)
#             x.state = 'confirm'
#         return True

    @api.one
    def finance_approve(self):
        precision = self.env['decimal.precision'].precision_get('bonus')
        self.env.cr.execute("""select current_date;""")
        xt = self.env.cr.fetchall()
        self.comment_date4 = xt[0][0]
        can_close = False
        move_obj = self.env['account.move']
        move_line_obj = self.env['account.move.line']
        currency_obj = self.env['res.currency']
        created_move_ids = []
        bonus_ids = []
        for bonus in self:
            bonus_ids = bonus.bonus_ids
            line_ids = []
            debit_sum = 0.0
            credit_sum = 0.0
            bonus_request_date = bonus.date
            for obj in bonus_ids:
                amount = obj.amount
                reference = bonus.journal_id.name
                journal_id = bonus.journal_id.id
                # currency_id = bonus.currency_id.id
                move_dict = {
                    'narration': reference,
                    'ref': reference,
                    'journal_id': journal_id,
                    # 'currency_id': currency_id,
                    'date': bonus_request_date,
                }

                debit_line = (
                    0,
                    0,
                    {
                        'name': reference,
                        'partner_id': False,
                        'account_id': bonus.account_id.id,
                        'journal_id': journal_id,
                        # 'currency_id': currency_id,
                        'date': bonus_request_date,
                        'debit': amount > 0.0 and amount or 0.0,
                        'credit': amount < 0.0 and -amount or 0.0,
                        'analytic_account_id': False,
                        'tax_line_id': 0.0,
                    })
                line_ids.append(debit_line)
                debit_sum += debit_line[2]['debit'] - debit_line[2]['credit']
                credit_line = (
                    0,
                    0,
                    {
                        'name': reference,
                        'partner_id': False,
                        'account_id': obj.account_id.id,
                        'journal_id': journal_id,
                        # 'currency_id': currency_id,
                        'date': bonus_request_date,
                        'debit': amount < 0.0 and -amount or 0.0,
                        'credit': amount > 0.0 and amount or 0.0,
                        'analytic_account_id': False,
                        'tax_line_id': 0.0,
                    })
                line_ids.append(credit_line)
                credit_sum += credit_line[2]['credit'] - credit_line[2]['debit']
                if float_compare(credit_sum,
                                 debit_sum,
                                 precision_digits=precision) == -1:
                    acc_journal_credit = bonus.journal_id.default_credit_account_id.id
                    if not acc_journal_credit:
                        raise UserError(
                            _('The Expense Journal "%s" has not properly configured the Credit Account!'
                              ) % (bonus.journal_id.name))
                    adjust_credit = (
                        0,
                        0,
                        {
                            'name': _('Adjustment Entry'),
                            'partner_id': False,
                            'account_id': acc_journal_credit,
                            'journal_id': journal_id,
                            # 'currency_id': currency_id,
                            'date': bonus_request_date,
                            'debit': 0.0,
                            'credit': debit_sum - credit_sum,
                        })
                    line_ids.append(adjust_credit)

                elif float_compare(debit_sum,
                                   credit_sum,
                                   precision_digits=precision) == -1:
                    acc_journal_deit = bonus.journal_id.default_debit_account_id.id
                    if not acc_journal_deit:
                        raise UserError(
                            _('The Expense Journal "%s" has not properly configured the Debit Account!'
                              ) % (bonus.journal_id.name))
                    adjust_debit = (
                        0,
                        0,
                        {
                            'name': _('Adjustment Entry'),
                            'partner_id': False,
                            'account_id': acc_journal_deit,
                            'journal_id': journal_id,
                            # 'currency_id': currency_id,
                            'date': bonus_request_date,
                            'debit': credit_sum - debit_sum,
                            'credit': 0.0,
                        })
                    line_ids.append(adjust_debit)

                move_dict['line_ids'] = line_ids
                move = self.env['account.move'].create(move_dict)
                bonus.write({'move_id': move.id, 'date': bonus_request_date})
                move.post()
            self.state = 'done'
            self.finance_request = True
Пример #11
0
class hr_overtime_month(models.Model):
    _name = 'hr.overtime.month'

    name = fields.Char(string='Overtime')
    date_from = fields.Date(string='Date From', required=True,
                            default=time.strftime('%Y-%m-01'))
    date_to = fields.Date(string='Date To', required=True,
                          default=str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10],
                          )
    overtime_line_ids = fields.One2many('overtime.line', 'overtime_line_id', string='Overtime Month')
    state = fields.Selection([
        ('draft', 'Draft'),
        ('confirm', 'Confirmed'),
        ('done', 'Done'),
        ('refuse', 'Refused'),
        ('auditor', 'Auditor')
    ], string="State", default='draft', track_visibility='onchange', copy=False, )

    journal_id = fields.Many2one('account.journal', string="Journal")
    overtime_account = fields.Many2one('account.account', string="Debit Account")
    account_id = fields.Many2one('account.account', string="Credit Account")
    move_id = fields.Many2one('account.move', string="Journal Entry", readonly=True)
    finance_request = fields.Boolean('Finance Request')

    @api.one
    def over_auditor(self):
        for x in self:
            x.state = 'auditor'

    @api.one
    def refuse(self):
        self.state = 'refuse'

    @api.multi
    def unlink(self):
        if any(self.filtered(lambda over: over.state not in ('draft', 'refuse'))):
            raise UserError(_('You cannot delete a Overtime which is not draft or cancelled!'))
        return super(hr_overtime_month, self).unlink()

    @api.depends('date_from', 'date_to')
    def compute_overtime_month(self):
        for x in self:
            locale = self.env.context.get('lang', 'en_US')
            overtime_obj = x.env['hr.overtime']
            overtime_line_obj = x.env['overtime.line']
            employee_obj = x.env['hr.employee'].search([])
            x.overtime_line_ids.unlink()
            for employee in employee_obj:
                employee_id = employee.id
                overtime_ids = overtime_obj.search(
                    [('overtime_date', '>=', x.date_from), ('overtime_date', '<=', x.date_to),
                     ('name', '=', employee_id), ('state', '=', 'done')], order='name')
                total_overtime = 0.0
                working_sum_hours = 0.0
                holiday_sum_hours = 0.0
                overtime_holiday = 0.0
                overtime_working = 0.0
                for overtime in overtime_ids:
                    employee_basic_salary = employee.contract_id.total_salary
                    employee_salary_hour = employee_basic_salary / 240
                    if overtime.is_working_day:
                        working_sum_hours += overtime.hour
                        overtime_working = working_sum_hours * employee_salary_hour * 1.5
                    if overtime.is_holiday:
                        holiday_sum_hours += overtime.hour
                        overtime_holiday = holiday_sum_hours * employee_salary_hour * 2
                    total_overtime = overtime_working + overtime_holiday
                if working_sum_hours != 0.0 or holiday_sum_hours != 0.0:
                    overtime_line_ids = overtime_line_obj.create({
                        'name': employee_id,
                        'overtime_month_working': working_sum_hours,
                        'overtime_month_holiday': holiday_sum_hours,
                        'overtime_month_value': total_overtime,
                        # 'employee_account': overtime.employee_account.id,
                        # 'analytic_debit_account_id': overtime.analytic_debit_account_id.id,
                        'overtime_line_id': x.id})
            x.state = 'confirm'

        return True


    @api.one
    def finance_approve(self):
        move_obj = self.env['account.move']
        move_line_obj = self.env['account.move.line']
        created_move_ids = []
        loan_ids = []
        amount_sum = 0.0
        for lta in self:
            lta_approve_date = fields.Date.today()
            journal_id = lta.journal_id.id
            reference = lta.name
            created_move_ids = []
            loan_ids = []

            line_ids = []
            debit_sum = 0.0
            credit_sum = 0.0
            for over in lta.overtime_line_ids:
                amount_sum += over.overtime_month_value

            lta_name = 'Overtime of ' + reference
            move_dict = {
                'narration': reference,
                'ref': reference,
                'journal_id': journal_id,
                'date': lta_approve_date,
            }

            debit_line = (0, 0, {
                'name': lta_name,
                'partner_id': False,
                'account_id': lta.overtime_account.id,
                'journal_id': journal_id,
                'move_id': self.move_id,
                'date': lta_approve_date,
                'debit': amount_sum > 0.0 and amount_sum or 0.0,
                'credit': amount_sum < 0.0 and -amount_sum or 0.0,
                'tax_line_id': 0.0,
            })
            line_ids.append(debit_line)
            debit_sum += debit_line[2]['debit'] - debit_line[2]['credit']
            credit_line = (0, 0, {
                'name': lta_name,
                'partner_id': False,
                'account_id': lta.account_id.id,
                'journal_id': journal_id,
                'move_id': self.move_id,
                'date': lta_approve_date,
                'debit': amount_sum < 0.0 and -amount_sum or 0.0,
                'credit': amount_sum > 0.0 and amount_sum or 0.0,
                'analytic_account_id': False,
                'tax_line_id': 0.0,
            })
            line_ids.append(credit_line)
            credit_sum += credit_line[2]['credit'] - credit_line[2]['debit']
            move_dict['line_ids'] = line_ids
            move = self.env['account.move'].create(move_dict)
            lta.write({'move_id': move.id, 'done_date': lta_approve_date})
            move.post()
        self.state = 'done'
Пример #12
0
class HrCustOvertime(models.Model):
    _name = 'hr.cust.overtime'

    def _default_employee(self):
        return self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1)

    name = fields.Many2one('hr.employee', string="Employee", default=_default_employee, required=True)
    user_id = fields.Many2one('res.users', 'Ordered by', readonly=True, default=lambda self: self.env.user)
    department_id = fields.Many2one('hr.department', related="name.department_id", readonly=True, string="Department")
    date_from = fields.Date(string='Date From', required=True,
                            default=time.strftime('%Y-%m-01'))
    date_to = fields.Date(string='Date To', required=True,
                          default=str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10],
                          )
    employee_account = fields.Many2one('account.account', string="Debit Account")
    overtime_line_ids = fields.One2many('hr.overtime', 'overtime_line_id', string='Overtime Line')

    state = fields.Selection([('draft', 'Draft'),
                              ('competent', 'Competent Department Manager'),
                              ('general', 'General Department Manager'),
                              ('approve', 'General HR Manager'),
                              ('hr', 'Hr Person'),
                              ('confirm', 'Hr Manager'),
                              ('account', 'Account'),
                              ('done', 'Done'), ('refuse', 'Refused')], 'State', default='draft')

    @api.multi
    def unlink(self):
        for rec in self:
            if rec.state not in ['draft']:
                raise UserError(_('You are not allow to delete the Confirm and Done state records'))
        res = super(HrCustOvertime, self).unlink()
        return res

    @api.one
    def to_competent(self):
        self.state = 'competent'

    @api.one
    def to_general(self):
        self.state = 'general'

    @api.one
    def to_approve(self):
        self.state = 'approve'

    @api.one
    def to_hr(self):
        self.state = 'hr'

    @api.one
    def to_Confirm(self):
        self.state = 'confirm'

    @api.one
    def action_done(self):
        self.state = 'done'
        for x in self.overtime_line_ids:
            x.state = 'done'

    @api.one
    def action_refuse(self):
        self.state = 'refuse'

    @api.one
    def action_reset(self):
        self.state = 'draft'

    @api.constrains('overtime_line_ids')
    def determine_overtime_day(self):
        for rec in self.overtime_line_ids:
            if not rec.is_working_day:
                if not rec.is_holiday:
                    raise Warning(_("Please determine work day of overtime is it work day or holiday day!"))
            if not rec.is_holiday:
                if not rec.is_working_day:
                    raise Warning(_("Please determine work day of overtime is it work day or holiday day!"))