Ejemplo n.º 1
0
class cosas(models.Model): 
    _name = 'ej.cosas' 
    cosa1 = fields.text(string='cosa1', required=True) 
 
    cosa2 = fields.integer(string='cosa2', required=True) 
 
    cosa3 = fields.text(string='cosa3', required=True) 
 
    cosa4 = fields.text(string='cosa4', required=True) 
 
    cosa5 = fields.text(string='cosa5', required=True) 
Ejemplo n.º 2
0
class citasmv(models.Model):
 _name = 'citasmv.citasmv'
  name = fields.char(string="Autor:", size=100, required=True),
  fecha = fields.date(string="Fecha de visualizaciòn:", required=True),
  description = fields.text(string="Descripciòn de la cita:", size=256, required=True),
  orden = fields.integer(string="Orden de visualizaciòn:", required=True)

  
Ejemplo n.º 3
0
class alumnos(models.Model):
    _name = 'alumnos.usuarios'
    _description = 'esta clase almacena alumnos'

    nombre = fields.Char()
    apellido = fields.Char()
    matricula = fields.Float(compute="_value_pc", store=True)
    numero = fields.Integer()
    memo = fields.text()
Ejemplo n.º 4
0
class WebsiteProposalTemplate(models.Model):
    _name = "website_proposal.template"
    _description = "Proposal Template"
    _columns = {
        'name':
        fields.char('Proposal Template', required=True),
        'head':
        fields.text('Html head'),
        'page_header':
        fields.html('Page header'),
        'website_description':
        fields.html('Description'),
        'page_footer':
        fields.html('Page footer'),
        'res_model':
        fields.char(
            'Model',
            help="The database object this template will be applied to"),
    }

    def open_template(self):
        return {
            'type': 'ir.actions.act_url',
            'target': 'self',
            'url': '/website_proposal/template/%d' % ids[0]
        }

    def create_proposal(self, template_id, res_id):
        if not template_id:
            return False
        if isinstance(template_id, list):
            template_id = template_id[0]

        template = self.env['website_proposal.template'].browse(template_id)

        vals = {
            'template_id': template_id,
            'head': template.head,
            'page_header': template.page_header,
            'website_description': template.website_description,
            'page_footer': template.page_footer,
            'res_id': res_id,
            'res_model': context.get('force_res_model') or template.res_model,
        }

        proposal_id = self.env['website_proposal.proposal'].create(
            vals, context)
        return proposal_id
Ejemplo n.º 5
0
class WebsiteProposal(models.Model):
    _name = 'website_proposal.proposal'
    _rec_name = 'id'

    def _get_default_company(self):
        company_id = self.env['res.users']._get_company(context=context)
        if not company_id:
            raise UserError(_('Error!'), _('There is no default company for the current user!'))
        return company_id

    def _get_res_name(self, name, args):
        res = {}
        for r in self.browse(ids):
            record = self.env[r.res_model].browse(r.res_id)
            res[r.id] = record.name
        return res

    _columns = {
        'res_name': fields.function(_get_res_name, string='Name', type='char'),
        'access_token': fields.char('Security Token', required=True, copy=False),
        'template_id': fields.many2one('website_proposal.template', 'Quote Template', readonly=True),
        'head': fields.text('Html head'),
        'page_header': fields.text('Page header'),
        'website_description': fields.html('Description'),
        'page_footer': fields.text('Page footer'),

        'res_model': fields.char('Model', readonly=True, help="The database object this is attached to"),
        'res_id': fields.integer('Resource ID', readonly=True, help="The record id this is attached to", select=True),
        'sign': fields.binary('Singature'),
        'sign_date': fields.datetime('Signing Date'),
        'signer': fields.binary('Signer'),
        'state': fields.selection([
            ('draft', 'Draft'),
            ('rejected', 'Rejected'),
            ('done', 'Signed'),
        ]),
        'company_id': fields.many2one('res.company', 'Company'),
    }
    _defaults = {
        'access_token': lambda self, cr, uid, ctx={}: str(uuid.uuid4()),
        'company_id': _get_default_company,
        'state': 'draft',
    }

    def open_proposal(self):
        return {
            'type': 'ir.actions.act_url',
            'target': 'self',
            'url': '/website_proposal/%s' % (ids[0])
        }

    def edit_proposal(self):
        return {
            'type': 'ir.actions.act_url',
            'target': 'self',
            'url': '/website_proposal/%s?enable_editor' % (ids[0])
        }

    def create(self, vals):
        record = self.env[vals.get('res_model']).browse(vals.get('res_id'))

        mako = mako_template_env.from_string(tools.ustr(vals.get('website_description')))
        website_description = mako.render({'record': record})
        website_description = website_description.replace('template-only-', '')

        vals['website_description'] = website_description
        new_id = super(WebsiteProposal, self).create(vals)
        return new_id
Ejemplo n.º 6
0
class SMSQueue(models.Model):
    _name = "moceansms.smsqueue"
    _description = "SMS Queue"

    action_time = fields.Datetime(
        'Action Time', readonly=True,  default=fields.Datetime.now())
    message = fields.Text(string="Message")
    recipient = fields.text(string="Recipient",help="Allow send to multiple recipient. Put (,) in between phone number.")
    connection_id = fields.Many2one("moceansms.smsconnection",
                                    "Connection"
                                    )
    state = fields.Selection([
        ('draft', 'Queued'),
        ('sending', 'Waiting'),
        ('send', 'Sent'),
        ('error', 'Error'),
    ],
        'Message Status',
        readonly=True,
        default='draft'
    )

    user_id = fields.Many2one(
        'res.users', string='Username', default=lambda self: self.env.user)
    reserve_key = fields.Char(size=30)
    send_to_all = fields.Boolean(default=False)

    def cron_sms(self):

        unique_key = time.time()
        self.env["moceansms.smsqueue"].search([("state", "=", "draft")]).write(
            {"reserve_key": unique_key, "state": "sending"})

        pending_sms = self.env["moceansms.smsqueue"].search(
            [("reserve_key", "=", unique_key)])
      

        for sms in pending_sms:
            
            params = {
                "mocean-api-key": sms.connection_id.api_key,
                "mocean-api-secret": sms.connection_id.api_secret,
                "mocean-from": sms.connection_id.sender_name,
                "mocean-to": sms.recipient,
                "mocean-text": sms.message,
                "mocean-resp-format": "JSON",
                "mocean-medium": "odoo"
            }

            if self.send(params) == True:
                params["state"] = "sent"
            else:
                params["state"] = "error"

            params["connection_id"] = sms.connection_id.id
            params["user_id"] = sms.user_id.id

            self.history(params, sms.connection_id)
            self.env["moceansms.smsqueue"].search(
                [("id", "=", sms.id)]).unlink()

    def send(self, data):
        url = 'https://rest.moceanapi.com/rest/2/sms'
    
        try:
            res = requests.post(url, data=data)
            res_data = res.json()
            if str(res.status_code) != "202":
                _logger.error("Fail to send sms due to %s" %
                              (res_data.err_msg))
                return False
        except Exception:
            _logger.error("Fail to send sms due to %s" % (e))
            return False
        return True

    def history(self, data, connection_id):
        self.env["moceansms.smshistory"].create({
            "recipient": data["mocean-to"],
            "message": data["mocean-text"],
            "state": data["state"],
            "connection_id": data["connection_id"],
            "user_id": data["user_id"]
        })
        return True

    def cron_mark_sms_expire(self):

        queue_sms = self.env["moceansms.smsqueue"].search(
            [("reserve_key", "!=", "")])
        current_time = time.time()

        for sms in queue_sms:

            expire_time = float(sms.reserve_key) + float("86400")

            if current_time > expire_time:
                self.env["moceansms.smsqueue"].search(
                    ["id", "=", sms.id]).unlink()

                self.history(
                    {
                        "mocean-to": sms.recipient,
                        "mocean-text": sms.message,
                        "user_id": sms.user_id,
                        "connection_id": sms.connction_id,
                        "state": "error"
                    }
                )