Exemplo n.º 1
0
 def create_sale_order_for_student(self):
     today = fields.Date.context_today(self)
     date_from = today.replace(month=1, day=1)
     next_year = today.year + 1
     date_to = today.replace(year=next_year, month=12, day=31)
     academic_years = self.env['education.academic_year'].search([
         ('date_start', '>=', date_from),
         ('date_end', '<=', date_to),
     ])
     if not academic_years:
         raise Warning(_('There are no valid academic years'))
     sales = self.env['sale.order']
     futures = self.mapped('future_student_ids').filtered(
         lambda l: l.child_id and not l.sale_order_id and
         l.academic_year_id in academic_years)
     if not futures:
         raise Warning(_('There are not future student to register.'))
     for future in futures:
         vals = future.crm_lead_id._get_vals_for_sale_order(future)
         future.sale_order_id = sales.create(vals)
         future.sale_order_id.onchange_sale_order_template_id()
         future.child_id.educational_category = 'student'
         future.crm_lead_id._put_payer_information_in_sale_order(
             future, future.sale_order_id)
         sales += future.sale_order_id
     action = self.env.ref('sale.action_quotations_with_onboarding')
     action_dict = action.read()[0] if action else {}
     domain = expression.AND([
         [('id', 'in', sales.ids)],
         safe_eval(action.domain or '[]')])
     action_dict.update({
         'domain': domain,
     })
     return action_dict
 def calculate_total_cost(self):
     for obj in self:
         obj.contract_price = obj.contract_rate * obj.total_cycles    
         if obj.per_user_pricing and obj.saas_users:
             if obj.saas_users < obj.min_users:
                 raise Warning("No. of users can't be less than %r"%obj.min_users)
             if obj.max_users != -1 and obj.saas_users > obj.max_users:
                 raise Warning("No. of users can't be greater than %r"%obj.max_users)
             obj.user_billing = obj.saas_users * obj.user_cost * obj.total_cycles
         obj.total_cost = obj.contract_price + obj.user_billing
         _logger.info("+++11++++OBJ>TOTALCOST+++++++%s",obj.total_cost)
Exemplo n.º 3
0
 def _on_change_url(self):
     self.ensure_one()
     if self.url:
         res = self._parse_document_url(self.url)
         if res.get('error'):
             raise Warning(
                 _('Could not fetch data from url. Document or access right not available:\n%s'
                   ) % res['error'])
         values = res['values']
         if not values.get('document_id'):
             raise Warning(
                 _('Please enter valid Youtube or Google Doc URL'))
         for key, value in values.items():
             self[key] = value
Exemplo n.º 4
0
 def _get_eu_res_country_group(self):
     eu_group = self.env.ref("base.europe", raise_if_not_found=False)
     if not eu_group:
         raise Warning(
             _('The Europe country group cannot be found. '
               'Please update the base module.'))
     return eu_group
Exemplo n.º 5
0
 def action_start_survey(self):
     self.ensure_one()
     if not self.stage_id.survey_id:
         raise Warning(_('Stage has no survey.'))
     response_obj = self.env['survey.user_input']
     response = response_obj.search([
         ('lead_id', '=', self.id),
         ('survey_id', '=', self.stage_id.survey_id.id),
     ],
                                    limit=1,
                                    order='date_create DESC')
     # create a response and link it to this applicant
     if not response:
         response = self.env['survey.user_input'].create({
             'survey_id':
             self.stage_id.survey_id.id,
             'lead_id':
             self.id,
             'partner_id':
             self.partner_id.id,
             'type':
             'manually',
         })
     # grab the token of the response and start surveying
     return self.stage_id.survey_id.with_context(
         survey_token=response.token).action_start_survey()
Exemplo n.º 6
0
 def write(self, vals):
     stage_obj = self.env['crm.stage']
     user_input_obj = self.env['survey.user_input']
     for record in self:
         if ('stage_id' in vals and
             (record.stage_id.survey_id and not record.user_input_ids.
              filtered(lambda u: u.state == 'done' and u.survey_id == record
                       .stage_id.survey_id))):
             raise Warning(_('Survey not answered.'))
         super(CrmLead, record).write(vals)
         if 'stage_id' in vals:
             stage = stage_obj.browse(vals.get('stage_id'))
             if stage.survey_id:
                 response = user_input_obj.search([
                     ('lead_id', '=', record.id),
                     ('survey_id', '=', stage.survey_id.id),
                 ])
                 if not response:
                     user_input_obj.create({
                         'survey_id': stage.survey_id.id,
                         'lead_id': record.id,
                         'partner_id': record.partner_id.id,
                         'type': 'manually',
                     })
     return True
    def action_create_contract(self):
        for obj in self:
            if obj.per_user_pricing:
                obj.user_billing = obj.saas_users * obj.user_cost * obj.total_cycles
                if obj.saas_users < obj.min_users and obj.max_users != -1 and obj.saas_users > obj.max_users:
                    raise Warning("Please select number of users in limit {} - {}".format(obj.min_users, obj.max_users))
            obj.total_cost = obj.contract_price + obj.user_billing
            vals = dict(
                partner_id=obj.partner_id and obj.partner_id.id or False,
                recurring_interval=obj.recurring_interval,
                recurring_rule_type=obj.recurring_rule_type,
                invoice_product_id=obj.invoice_product_id and obj.invoice_product_id.id or False,
                pricelist_id=obj.partner_id.property_product_pricelist and obj.partner_id.property_product_pricelist.id or False,
                currency_id=obj.partner_id.property_product_pricelist and obj.partner_id.property_product_pricelist.currency_id and obj.partner_id.property_product_pricelist.currency_id.id or False,
                start_date=obj.start_date,
                total_cycles=obj.total_cycles,
                trial_period=obj.trial_period,
                remaining_cycles=obj.total_cycles,
                next_invoice_date=obj.start_date,
                contract_rate=obj.contract_rate,
                contract_price=obj.contract_price,
                due_users_price=obj.due_users_price,
                total_cost=obj.total_cost,
                per_user_pricing=obj.per_user_pricing,
                user_billing=obj.user_billing,
                user_cost=obj.user_cost,
                saas_users=obj.saas_users,
                min_users=obj.min_users,
                max_users=obj.max_users,
                auto_create_invoice=obj.auto_create_invoice,
                saas_module_ids=[(6, 0 , obj.plan_id.saas_module_ids.ids)],
                server_id=obj.plan_id.server_id.id,
                db_template=obj.plan_id.db_template,
                plan_id=obj.plan_id.id,
                from_backend=True,
            )

            try:
                _logger.info("!!!!!!!===!!!!!!!!%s",obj.total_cost)
                record_id = self.env['saas.contract'].create(vals)
                _logger.info("--------Contract--Created-------%r", record_id)
            except Exception as e:
                _logger.info("--------Exception-While-Creating-Contract-------%r", e)
            else:
                imd = self.env['ir.model.data']
                action = imd.xmlid_to_object('eagle_saas_kit.saas_contract_action')
                list_view_id = imd.xmlid_to_res_id('eagle_saas_kit.saas_contract_tree_view')
                form_view_id = imd.xmlid_to_res_id('eagle_saas_kit.saas_contract_form_view')

                return {
                    'name': action.name,
                    'res_id': record_id.id,
                    'type': action.type,
                    'views': [[form_view_id, 'form'], [list_view_id, 'tree'], ],
                    'target': action.target,
                    'context': action.context,
                    'res_model': action.res_model,
                }
Exemplo n.º 8
0
 def create(self, vals):
     if vals.get('recurring_interval', 0) <= 0:
         raise Warning("Default Billing Cycle can't be less than 1")
     res = super(SaasPlans, self).create(vals)
     for obj in res:
         if obj.name and not obj.db_template:
             template_name = obj.name.lower().replace(" ", "_")
             obj.db_template = "{}_tid_{}".format(template_name, res.id)
     return res
Exemplo n.º 9
0
 def create(self, vals):
     if self.env.user.child_ids:
         raise Warning(
             _('Invalid Action!\n Parent can not create \
         Media Queue Requests!'))
     if vals.get('name', '/') == '/':
         vals['name'] = self.env['ir.sequence'].next_by_code(
             'op.media.queue') or '/'
     return super(OpMediaQueue, self).create(vals)
Exemplo n.º 10
0
def pre_init_check(cr):
    from eagle.service import common
    from eagle.exceptions import Warning
    version_info = common.exp_version()
    server_serie = version_info.get('server_serie')
    if server_serie != '13.0':
        raise Warning(
            'Module support Eagle series 13.0 found {}.'.format(server_serie))
    return True
Exemplo n.º 11
0
 def force_confirm(self):
     for obj in self:
         response = None
         if not obj.container_id:
             _, db_server = obj.server_id.get_server_details()
             response = query.is_db_exist(obj.db_template,
                                          db_server=db_server)
             if not response:
                 raise Warning("Please create DB Template First!")
         obj.state = 'confirm'
Exemplo n.º 12
0
    def _get_company_legal_data(self, company):
        """
        Dom-Tom are excluded from the EU's fiscal territory
        Those regions do not have SIREN
        sources:
            https://www.service-public.fr/professionnels-entreprises/vosdroits/F23570
            http://www.douane.gouv.fr/articles/a11024-tva-dans-les-dom
        """
        dom_tom_group = self.env.ref('l10n_fr.dom-tom')
        is_dom_tom = company.country_id.code in dom_tom_group.country_ids.mapped(
            'code')
        if not is_dom_tom and not company.vat:
            raise Warning(
                _("Missing VAT number for company %s") % company.name)
        if not is_dom_tom and company.vat[0:2] != 'FR':
            raise Warning(_("FEC is for French companies only !"))

        return {
            'siren': company.vat[4:13] if not is_dom_tom else '',
        }
Exemplo n.º 13
0
 def action_confirm(self):
     res = super(SaleOrder, self).action_confirm()
     for sale in self:
         recurrent_lines = sale.order_line.filtered(
             lambda l: l.product_id.recurrent_punctual)
         if any(recurrent_lines.filtered(
                 lambda l: not l.originator_id or not l.payer_ids)):
             raise Warning(_('Please check out originator and payer for '
                             'recurrent/punctual products.'))
         for line in recurrent_lines:
             line.create_contract_line()
     return res
Exemplo n.º 14
0
    def relation_transform(self, pool_src, pool_dest, obj_model, res_id,
                           action, destination_inverted):
        if not res_id:
            return False
        _logger.debug("Relation transform")
        self._cr.execute(
            '''select o.id from base_synchro_obj o left join
                        ir_model m on (o.model_id =m.id) where
                        m.model=%s and o.active''', (obj_model, ))
        obj = self._cr.fetchone()
        result = False
        if obj:
            result = self.get_id(obj[0], res_id, action)
            _logger.debug(
                "Relation object already synchronized. Getting id %s", result)
        else:
            _logger.debug('Relation object not synchronized. Searching \
             by name_get and name_search')
            if not destination_inverted:
                names = pool_src.get(obj_model).name_get([res_id])[0][1]
                res = pool_dest.env[obj_model].name_search(
                    names, [], 'like', 1)
                res = res and res[0][0] or False
            else:
                pool = pool_src.env[obj_model]
                names = pool.browse([res_id]).name_get()[0][1]
                try:
                    rec_name = pool_src.env[obj_model]._rec_name
                    res = pool_dest.get(obj_model).search(
                        [(rec_name, '=', names)], 1)
                    res = res and res[0] or False
                except Exception as e:
                    raise Warning(_(e))

            _logger.debug("name_get in src: %s", names)
            _logger.debug("name_search in dest: %s", res)
            if res:
                result = res
            else:
                _logger.warning(
                    "Record '%s' on relation %s not found, set to null.",
                    names, obj_model)
                _logger.warning(
                    "You should consider synchronize this model '%s'",
                    obj_model)
                self.report.append(
                    'WARNING: Record "%s" on relation %s not found, set to\
                     null.' % (names, obj_model))
        return result
Exemplo n.º 15
0
 def __init__(self, server, ressource):
     """Class to store one RPC proxy server."""
     self.server = server
     local_url = 'http://%s:%d/xmlrpc/common' % (server.server_url,
                                                 server.server_port)
     try:
         rpc = ServerProxy(local_url, allow_none=True)
         self.uid = rpc.login(server.server_db, server.login,
                              server.password)
     except Exception as e:
         raise Warning(_(e))
     local_url = 'http://%s:%d/xmlrpc/object' % (server.server_url,
                                                 server.server_port)
     self.rpc = ServerProxy(local_url, allow_none=True)
     self.ressource = ressource
Exemplo n.º 16
0
 def create(self, vals):
     if self.env.user.child_ids:
         raise Warning(
             _('Invalid Action!\n Parent can not create \
         Media Purchase Requests!'))
     return super(OpMediaPurchase, self).create(vals)
Exemplo n.º 17
0
 def write(self, vals):
     if self.env.user.child_ids:
         raise Warning(
             _('Invalid Action!\n Parent can not edit \
         Media Queue Requests!'))
     return super(OpMediaQueue, self).write(vals)
Exemplo n.º 18
0
 def write(self, vals):
     if vals.get('recurring_interval',
                 False) and vals['recurring_interval'] <= 0:
         raise Warning("Default Billing Cycle can't be less than 1")
     res = super(SaasPlans, self).write(vals)
     return res
Exemplo n.º 19
0
 def confirm_disable(self):
     raise Warning("ok")
Exemplo n.º 20
0
 def unlink(self):
     for obj in self:
         raise Warning("Can't Delete Clients")
Exemplo n.º 21
0
    def synchronize(self, server, object):
        sync_ids = []
        pool1 = RPCProxy(server)
        pool2 = self
        dt = object.synchronize_date
        module = pool1.get('ir.module.module')
        model_obj = object.model_id.model
        avoid_field_list = [a.name for a in object.avoid_ids]

        if module.search_count([("name", "ilike", "base_synchro"),
                                ('state', '=', 'installed')]) < 1:
            raise Warning(
                _('If your Synchronization direction is \
                          download and/or upload, please install \
                          "Multi-DB Synchronization" module in targeted \
                          server!'))
        if object.action in ('d', 'b'):
            sync_ids = pool1.get('base.synchro.obj').get_ids(
                model_obj, dt, eval(object.domain), {'action': 'd'})
        if object.action in ('u', 'b'):
            _logger.debug("Getting ids to synchronize [%s] (%s)",
                          object.synchronize_date, object.domain)

            sync_ids += pool2.env['base.synchro.obj'].get_ids(
                model_obj, dt, eval(object.domain), {'action': 'u'})
        for dt, sync_id, action in sync_ids:
            destination_inverted = False
            if action == 'd':
                pool_src = pool1
                pool_dest = pool2
            else:
                pool_src = pool2
                pool_dest = pool1
                destination_inverted = True
            if not destination_inverted:
                value = pool_src.get(object.model_id.model).search_read([
                    ('id', '=', sync_id)
                ])[0]
            else:
                pool = pool_src.env[object.model_id.model]
                value = pool.search_read([('id', '=', sync_id)])[0]
            avoid_field_list += ['create_date', 'write_date']

            field_vals = dict([
                (key, val[0] if isinstance(val, tuple) else val)
                for key, val in filter(lambda i: i[0] not in avoid_field_list,
                                       value.items())
            ])

            value = self.data_transform(pool_src, pool_dest,
                                        object.model_id.model, field_vals,
                                        action, destination_inverted,
                                        avoid_field_list)
            id2 = self.get_id(object.id, sync_id, action)
            if id2:
                _logger.debug("Updating model %s [%d]", object.model_id.name,
                              id2)
                if not destination_inverted:
                    pool = pool_dest.env[object.model_id.model]
                    pool.browse([id2]).update(value)
                else:
                    pool_dest.get(object.model_id.model).write(id2, value)
                self.report_total += 1
                self.report_write += 1
            else:
                _logger.debug("Creating model %s", object.model_id.name)
                try:
                    if not destination_inverted:
                        new_id = pool_dest.env[object.model_id.model].create(
                            value).id
                    else:
                        new_id = pool_dest.get(
                            object.model_id.model).create(value)
                except Exception as e:
                    raise Warning(_(e))
                self.env['base.synchro.obj.line'].create({
                    'obj_id':
                    object.id,
                    'local_id': (action == 'u') and sync_id or new_id,
                    'remote_id': (action == 'd') and sync_id or new_id
                })
                self.report_total += 1
                self.report_create += 1
        return True