Пример #1
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.iteritems():
             setattr(self, key, value)
Пример #2
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
Пример #3
0
 def cancel(self):
     if not self.env.context.get('bank_statement_cancel'):
         for line in self:
             if line.statement_id.state == 'confirm':
                 raise Warning(
                     _("Please set the bank statement to New before canceling."
                       ))
     return super(BankStatementLine, self).cancel()
Пример #4
0
 def write(self, vals):
     if vals.has_key('forecast_filter_id'):
         vals['forecast_filter_id'] = False
     if vals.has_key('period_count'):
         if vals['period_count'] <= 0:
             raise Warning(
                 _('Number of Periods should be grater than zero'))
     return super(sale_forecast, self).write(vals)
Пример #5
0
 def _check_recursion(self):
     level = 100
     cr = self.env.cr
     ids = self.ids
     while len(ids):
         cr.execute('select distinct parent_id from saas_portal_category where id IN %s', (tuple(ids), ))
         ids = filter(None, map(lambda x:x[0], cr.fetchall()))
         if not level:
             raise Warning('Error! You cannot create recursive Categories')
         level -= 1
     return True
Пример #6
0
    def action_backup(self):
        '''
        call to backup database
        '''
        self.ensure_one()
        if not self[0].backup:
            return
        state = {
            'd': self.name,
            'client_id': self.client_id,
        }

        url = self.server_id._request_server(path='/saas_server/backup_database', state=state, client_id=self.client_id)[0]
        res = requests.get(url, verify=(self.server_id.request_scheme == 'https' and self.server_id.verify_ssl))
        _logger.info('delete database: %s', res.text)
        if res.ok != True:
            raise Warning('Reason: %s \n Message: %s' % (res.reason, res.content))
        data = simplejson.loads(res.text)
        if data[0]['status'] != 'success':
            warning = data[0].get('message', 'Could not backup database; please check your logs')
            raise Warning(warning)
        return True
Пример #7
0
    def perform_action(self):
        if self.create_action:
            if self.state != 'confirm':
                raise Warning(_('Forecast State should be Confirmed'))
            procurement_order_obj = self.env['procurement.order']
            supplier_obj = self.env['product.supplierinfo']
            res_company_obj = self.env['res.company']
            forecast_product_obj = self.env['forecast.product']

            for line in self.forecast_product_ids:
                line_product_id = line.product_id
                line_prod_temp_id = line.product_id.product_tmpl_id
                line_route_ids = self.env['product.template'].search([
                    ('id', '=', line_prod_temp_id.id)
                ]).route_ids
                mto_route_id = self.env['stock.location.route'].search([
                    ('name', '=', 'Make To Order')
                ]).id

                company_id = line.product_id.company_id
                company_rec = res_company_obj.search([('id', '=',
                                                       company_id.id)])
                if line_route_ids:
                    if not line_route_ids.filtered(
                            lambda r: r.id == mto_route_id
                    ) and line.action_qty > 0 and line.action_required != 'none':
                        # To check whether type of product is Stockable
                        if line_prod_temp_id.type == 'product':
                            if line.action_required == 'buy':
                                route_id = self.env[
                                    'stock.location.route'].search([
                                        ('name', '=', 'Buy')
                                    ]).id
                                routes = route_id and [(4, route_id)] or []
                                picking_type_id = self.env[
                                    'stock.warehouse'].search([
                                        ('id', '=', self.warehouse_id.id)
                                    ]).in_type_id
                                location_id = self.env[
                                    'stock.picking.type'].search([
                                        ('id', '=', picking_type_id.id)
                                    ]).default_location_dest_id
                            elif line.action_required in ('manufacture',
                                                          'both'):
                                route_id = self.env[
                                    'stock.location.route'].search([
                                        ('name', '=', 'Manufacture')
                                    ]).id
                                routes = route_id and [(4, route_id)] or []
                                picking_type_id = self.env[
                                    'stock.warehouse'].search([
                                        ('id', '=', self.warehouse_id.id)
                                    ]).int_type_id
                                location_id = self.env[
                                    'stock.picking.type'].search([
                                        ('id', '=', picking_type_id.id)
                                    ]).default_location_dest_id

                            # routes = line_route_ids and [(4, line_route_ids.id)] or []
                            date_planned = datetime.strptime(
                                line.period_start_date,
                                DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                                    days=company_rec.security_lead)
                            procurement_date_planned = date_planned.strftime(
                                DEFAULT_SERVER_DATE_FORMAT)

                            vals = {
                                # 'product_uos_qty':
                                'product_uom': line_prod_temp_id.uom_id.id,
                                'warehouse_id': self.warehouse_id.id,
                                'location_id': location_id.id,
                                'route_ids': routes,
                                'product_qty': line.action_qty,
                                # 'product_uos': line_prod_temp_id.uos_id,
                                'product_id': line_product_id.id,
                                'name': line_product_id.name,
                                'date_planned': procurement_date_planned,
                                'company_id': company_id.id,
                                'forecast_ref_procurement': self.id,
                            }
                            procurement_id = procurement_order_obj.create(
                                vals).id
                            procurement_order_rec_state = procurement_order_obj.search(
                                [('id', '=', procurement_id)]).state
                            if line.action_required == 'buy':
                                if procurement_order_rec_state == 'exception':
                                    document_number = 'Exception'
                                elif procurement_order_rec_state == 'running':
                                    purchase_order_rec = procurement_order_obj.search(
                                        [('id', '=', procurement_id)
                                         ]).purchase_id
                                    document_number = self.env[
                                        'purchase.order'].search([
                                            ('id', '=', purchase_order_rec.id)
                                        ]).name

                            elif line.action_required in ('manufacture',
                                                          'both'):
                                if procurement_order_rec_state == 'exception':
                                    document_number = 'Exception'
                                elif procurement_order_rec_state == 'running':
                                    mrp_production_rec = procurement_order_obj.search(
                                        [('id', '=', procurement_id)
                                         ]).production_id
                                    document_number = self.env[
                                        'mrp.production'].search([
                                            ('id', '=', mrp_production_rec.id)
                                        ]).name
                            forecast_product_obj.browse(line.id).write({
                                'document_number':
                                document_number,
                                'procurement_id':
                                procurement_id
                            })
                self.state = 'done'
Пример #8
0
    def generate_forecast(self):
        self.record_generated = True
        order_obj = self.env['sale.order']
        order_line_obj = self.env['sale.order.line']
        for rec in self:
            rec.write({'forecast_product_ids': [(5, 0)]})
        forecast_product_obj = self.env['forecast.product']
        if self.period and self.start_date and self.period_count:
            periods = self.get_period(self.period, self.start_date,
                                      self.period_count)
        elif self.period_count <= 0:
            raise Warning(_('Number of Periods should be grater than Zero'))
        if self.product_ids:
            domain = eval(self.product_ids)
            product_ids = self.env['product.product'].search(domain)
        else:
            raise Warning(_('Atleast one product should be selected!'))
        if not self.warehouse_id:
            raise Warning(_('Warehouse should be selected!'))
        first_period = True
        for index, item in enumerate(periods):
            if self.period == 'week':
                expected_end_date = datetime.strptime(
                    item.name,
                    DEFAULT_SERVER_DATE_FORMAT) + relativedelta(weeks=1)
                end_date = expected_end_date.strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                previous_rec_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        weeks=1) - relativedelta(days=1)
                previous_rec_start_date = previous_rec_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                sec_last_period_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        weeks=2) - relativedelta(days=2)
                sec_last_start_date = sec_last_period_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                third_last_period_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        weeks=3) - relativedelta(days=3)
                third_last_start_date = third_last_period_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
            elif self.period == 'month':
                expected_end_date = datetime.strptime(
                    item.name,
                    DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=1)
                end_date = expected_end_date.strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                previous_rec_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        months=1) - relativedelta(days=1)
                previous_rec_start_date = previous_rec_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                sec_last_period_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        months=2) - relativedelta(days=2)
                sec_last_start_date = sec_last_period_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                third_last_period_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        months=3) - relativedelta(days=3)
                third_last_start_date = third_last_period_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
            elif self.period == 'quarter':
                expected_end_date = datetime.strptime(
                    item.name,
                    DEFAULT_SERVER_DATE_FORMAT) + relativedelta(months=3)
                end_date = expected_end_date.strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                previous_rec_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        months=3) - relativedelta(days=1)
                previous_rec_start_date = previous_rec_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                sec_last_period_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        months=6) - relativedelta(days=2)
                sec_last_start_date = sec_last_period_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                third_last_period_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        months=9) - relativedelta(days=3)
                third_last_start_date = third_last_period_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
            elif self.period == 'year':
                expected_end_date = datetime.strptime(
                    item.name,
                    DEFAULT_SERVER_DATE_FORMAT) + relativedelta(years=1)
                end_date = expected_end_date.strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                previous_rec_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        years=1) - relativedelta(days=1)
                previous_rec_start_date = previous_rec_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                sec_last_period_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        years=2) - relativedelta(days=2)
                sec_last_start_date = sec_last_period_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
                third_last_period_date = datetime.strptime(
                    self.start_date,
                    DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                        years=3) - relativedelta(days=3)
                third_last_start_date = third_last_period_date.date().strftime(
                    DEFAULT_SERVER_DATE_FORMAT)
            for product in product_ids:
                product_template_id = product.product_tmpl_id
                routes = self.env['product.template'].search([
                    ('id', '=', product_template_id.id)
                ]).route_ids
                mto_route_id = self.env['stock.location.route'].search([
                    ('name', '=', 'Make To Order')
                ]).id
                if routes:
                    if routes.filtered(lambda r: r.id == mto_route_id):
                        action = 'none'
                    else:
                        if routes.filtered(
                                lambda r: r.name == 'Buy') and routes.filtered(
                                    lambda r: r.name == 'Manufacture'):
                            action = 'both'
                        else:
                            for route in routes:
                                if route.name == 'Buy':
                                    action = 'buy'
                                elif route.name == 'Manufacture':
                                    action = 'manufacture'
                else:
                    action = 'none'
                ctx = self._context.copy()
                ctx.update({
                    'from_date': item.name,
                    'to_date': end_date,
                    'warehouse': self.warehouse_id.id,
                    'current_model': self._model,
                    'rec_id': self.id
                })
                product_qty = self.pool.get(
                    'product.product')._product_available(
                        self._cr, self._uid, [product.id], False, False, ctx)
                qty_list = product_qty.get(product.id)
                last_period_qty, sec_last_period_qty, third_last_period_qty, avg_qty = 0.0, 0.0, 0.0, 0.0
                if first_period == True:
                    new_rest_period_qty = qty_list['qty_available']
                    available_qty = new_rest_period_qty
                    forecast_product_rec = self.env['forecast.product']
                    forecast_product_last_recs = forecast_product_rec.search([
                        ('period_start_date', '=', previous_rec_start_date),
                        ('product_id', '=', product.id)
                    ])
                    if forecast_product_last_recs:
                        last_period_qty = forecast_product_last_recs[
                            0].forecast_qty
                    forecast_product_sec_last_recs = forecast_product_rec.search(
                        [('period_start_date', '=', sec_last_start_date),
                         ('product_id', '=', product.id)])
                    if forecast_product_sec_last_recs:
                        sec_last_period_qty = forecast_product_sec_last_recs[
                            0].forecast_qty
                    forecast_product_third_last_recs = forecast_product_rec.search(
                        [('period_start_date', '=', third_last_start_date),
                         ('product_id', '=', product.id)])
                    if forecast_product_third_last_recs:
                        third_last_period_qty = forecast_product_third_last_recs[
                            0].forecast_qty
                    if last_period_qty or sec_last_period_qty or third_last_period_qty:
                        avg_qty = (last_period_qty + sec_last_period_qty +
                                   third_last_period_qty) / 3
                    previous_start_date = self.start_date
                    sale_qty = 0.0
                    for i in range(1, 12):
                        if self.period == 'week':
                            previous_new_rec_date = datetime.strptime(
                                previous_start_date,
                                DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                                    weeks=1) - relativedelta(days=1)
                        elif self.period == 'month':
                            previous_new_rec_date = datetime.strptime(
                                previous_start_date,
                                DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                                    months=1) - relativedelta(days=1)
                        elif self.period == 'quarter':
                            previous_new_rec_date = datetime.strptime(
                                previous_start_date,
                                DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                                    months=3) - relativedelta(days=1)
                        elif self.period == 'year':
                            previous_new_rec_date = datetime.strptime(
                                previous_start_date,
                                DEFAULT_SERVER_DATE_FORMAT) - relativedelta(
                                    years=1) - relativedelta(days=1)
                        previous_new_rec_date = previous_new_rec_date.strftime(
                            DEFAULT_SERVER_DATE_FORMAT)
                        order_recs = order_obj.search([
                            ('date_order', '<=', previous_start_date),
                            ('date_order', '>=', previous_new_rec_date)
                        ])
                        if order_recs:
                            for order_rec in order_recs:
                                order_line_recs = order_line_obj.search([
                                    ('order_id', '=', order_rec[0].id),
                                    ('product_id', '=', product.id)
                                ])
                                if order_line_recs:
                                    for order_line_rec in order_line_recs:
                                        sale_qty = sale_qty + order_line_rec.product_uom_qty
                        previous_start_date = previous_new_rec_date
                    if sale_qty:
                        avg_sale_qty = sale_qty / 12
                    else:
                        avg_sale_qty = 0.0
                else:
                    available_qty = 0.0

                vals = {
                    'name': product.name + ' on ' + str(item.name),
                    'forecast_id': self.id,
                    'product_id': product.id,
                    'period_start_date': item.name,
                    'period_end_date': end_date,
                    'onhand_qty': available_qty,
                    'last_period_qty': last_period_qty,
                    'sec_last_period_qty': sec_last_period_qty,
                    'third_last_period_qty': third_last_period_qty,
                    'incoming_qty': qty_list['incoming_qty'],
                    'outgoing_qty': qty_list['outgoing_qty'],
                    'rest_period_qty': available_qty,
                    'action_required': action,
                    'avg_qty': avg_qty,
                    'avg_sale_qty': round(avg_sale_qty or 0.0),
                }
                created_id = forecast_product_obj.create(vals)
            first_period = False
Пример #9
0
 def create(self, vals):
     if vals.has_key('period_count'):
         if vals['period_count'] < 0:
             raise Warning(
                 _('Number of Periods should not be less than zero'))
     return super(sale_forecast, self).create(vals)
Пример #10
0
 def copy(self, default=None):
     raise Warning(_('Forecast Record Can not be Duplicated'))