def _check_aluno(self): # Campos vazios if not self.nr_mecanografico or not self.name: raise models.ValidationError( 'Um Aluno deve possuir um nº mecanográfico, um email, um nome e uma password !' ) # ID unico if len(self.env['transum.aluno'].search( [('nr_mecanografico', '=', self.nr_mecanografico)])) > 1: raise models.ValidationError( 'O número mecanográfico introduzido já está associado a outro Aluno !' ) # Curso if not self.curso_id: raise models.ValidationError( 'Um Aluno deve possuir pelo menos um Curso !') # Existir um plano de curso associado ao Curso for curso in self.curso_id: curso = self.env['transum.curso'].search([('id', '=', curso.id)]) if not len(curso.get_plano_curso()) > 0: raise models.ValidationError( 'O Curso escolhido não possui um Plano de Curso associado !' )
def button_cancel(self): res_obj=self.env['res.config.settings'].get_values() if not res_obj['finance_assistant']: raise models.ValidationError(_('There is no value set for Finance Assistant in configuration settings. Please contact the system administrator')) #get employee confirm_emp=self.env['hr.employee'].sudo().search([('id','=',res_obj['finance_assistant'])]) if not confirm_emp: raise models.ValidationError(_('There is no employee for value of Finance Assistant in configuration settings. Please contact the system administrator')) #validate login user against confirm_emp if confirm_emp.user_id.id!=self.env.uid and confirm_emp.parent_id.user_id.id!=self.env.uid: raise ValidationError(('''Solo %s o su Jefe Directo, %s pueden mandar esta O/C a Facturar''') % (confirm_emp.name,confirm_emp.parent_id.name)) for order in self: #we need to get approver params fro m res.config for inv in order.invoice_ids: if inv and inv.state not in ('cancel', 'draft'): raise UserError(_("Unable to cancel this purchase order. You must first cancel the related vendor bills.")) self.write({'state': 'cancel'})
def _check_email(self): if len(self.email) < 7: raise models.ValidationError( 'El mail debe constar de al menos 7 caracteres') if re.match("^.+@(\[?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,3}|[0-9]{1,3})(]?)$", self.email) == None: raise models.ValidationError( 'El formato del email debe ser [email protected]')
def _comprobar_pai(self): for equipo in self: if equipo.usuarios_ids and equipo.usuarios_ids.parent_id != equipo.propietario_id: raise models.ValidationError( 'O usuario debe pertencer ó cliente especificado') if equipo.sede_id and equipo.sede_id.parent_id != equipo.propietario_id: raise models.ValidationError( 'A sede debe pertencer ó cliente especificado')
def add_orders_to_dispatch(self): if self.is_multiple_dispatch: if not self.sale_orders_id: raise models.ValidationError( 'No se selecciono ningun numero de pedido') if not self.dispatch_id: raise models.ValidationError( 'No se selecciono ningun despacho') if self.dispatch_id in self.dispatch_line_ids.mapped( 'dispatch_id'): raise models.ValidationError( 'El despacho {} ya se encuentra agregado'.format( self.dispatch_id.id)) for product in self.dispatch_id.move_ids_without_package: self.env['custom.dispatch.line'].create({ 'dispatch_real_id': self.id, 'dispatch_id': self.dispatch_id.id, 'sale_id': self.sale_orders_id.id, 'product_id': product.product_id.id, 'required_sale_qty': product.product_uom_qty, }) # No existe producto if not self.move_ids_without_package.filtered( lambda p: p.product_id.id == product.product_id.id): self.env['stock.move'].create({ 'product_id': product.product_id.id, 'picking_id': self.id, 'product_uom': product.product_id.uom_id.id, 'product_uom_qty': product.product_uom_qty, 'date': datetime.date.today(), 'date_expected': self.scheduled_date, 'location_dest_id': self.partner_id.property_stock_customer.id, 'location_id': self.location_id.id, 'name': product.product_id.name, 'procure_method': 'make_to_stock', }) else: move = self.move_ids_without_package.filtered( lambda p: p.product_id.id == product.product_id.id) move.write({ 'product_uom_qty': move.product_uom_qty + product.product_uom_qty })
def _check_quantity(self): for sale in self: if sale.quantity > sale.product.stock: raise models.ValidationError('There is not enough stock') else: sale.product.stock = sale.product.stock - sale.quantity if sale.quantity < 0: raise models.ValidationError('Quantity must be a positive number')
def action_view_invoice(self): ''' This function returns an action that display existing vendor bills of given purchase order ids. When only one found, show the vendor bill immediately. ''' #we need to get approver params fro m res.config res_obj=self.env['res.config.settings'].get_values() if not res_obj['finance_assistant']: raise models.ValidationError(_('There is no value set for Finance Assistant in configuration settings. Please contact the system administrator')) #get employee confirm_emp=self.env['hr.employee'].sudo().search([('id','=',res_obj['finance_assistant'])]) if not confirm_emp: raise models.ValidationError(_('There is no employee for value of Finance Assistant in configuration settings. Please contact the system administrator')) #validate login user against confirm_emp if confirm_emp.user_id.id!=self.env.uid and confirm_emp.parent_id.user_id.id!=self.env.uid: raise ValidationError(('''Solo %s o su Jefe Directo, %s pueden mandar esta O/C a Facturar''') % (confirm_emp.name,confirm_emp.parent_id.name)) action = self.env.ref('account.action_vendor_bill_template') result = action.read()[0] create_bill = self.env.context.get('create_bill', False) # override the context to get rid of the default filtering result['context'] = { 'type': 'in_invoice', 'default_purchase_id': self.id, 'default_currency_id': self.currency_id.id, 'default_company_id': self.company_id.id, 'company_id': self.company_id.id } # choose the view_mode accordingly if len(self.invoice_ids) > 1 and not create_bill: result['domain'] = "[('id', 'in', " + str(self.invoice_ids.ids) + ")]" else: res = self.env.ref('account.invoice_supplier_form', False) form_view = [(res and res.id or False, 'form')] if 'views' in result: result['views'] = form_view + [(state,view) for state,view in action['views'] if view != 'form'] else: result['views'] = form_view # Do not set an invoice_id if we want to create a new bill. if not create_bill: result['res_id'] = self.invoice_ids.id or False result['context']['default_origin'] = self.name result['context']['default_reference'] = self.partner_ref _logger.info("result=%s",result) return result
def _check_uc(self): # Campos vazios if not self.designacao or not self.codigo: raise models.ValidationError( 'Uma Unidade Curricular deve possuir um código e uma designação !' ) # ID unico if len(self.env['transum.uc'].search([('codigo', '=', self.codigo) ])) > 1: raise models.ValidationError( 'O código introduzido já está associado a outra Unidade Curricular !' )
def _check_season_reliability(self): """ Forbid registration when member season if not coherent with activity season or are duplicates """ for reg in self: if (reg.activity_id.only_for_subscriber and \ reg.member_id.membership_state in ['none', 'canceled', 'old']): emsg = _('Subscription can not be executed : the targeted ' 'activity is only for subscriber.') raise models.ValidationError(emsg) if reg.activity_id.season_id not in reg.member_id.season_ids: emsg = _('Subscription can not be executed : the targeted ' 'member is not on the same season as the activity.') raise models.ValidationError(emsg)