def raise_user_warning(cls, warning_name, warning, warning_args=None, warning_description='', warning_description_args=None): ''' Raise an exception that will be displayed as a warning message in the client, if the user has not yet bypassed it. :param warning_name: the unique warning name :param warning: the key of the dictionary _error_messages used for warning message :param warning_args: the arguments that will be used for "%"-based substitution :param warning_description: the key of the dictionary _error_messages used for warning description :param warning_description_args: the arguments that will be used for "%"-based substitution ''' Warning_ = Pool().get('res.user.warning') if Warning_.check(warning_name): if warning_description: warning, warning_description = cls.raise_user_error( warning, error_args=warning_args, error_description=warning_description, error_description_args=warning_description_args, raise_exception=False) raise UserWarning(warning_name, warning, warning_description) else: warning = cls.raise_user_error(warning, error_args=warning_args, raise_exception=False) raise UserWarning(warning_name, warning)
def confirm(cls, sales): Warning = Pool().get('res.user.warning') # make sure noone is able to confirm a sale with shipment or invoice methods we do not want for sale in sales: if sale.shipment_method != 'order': raise UserError('Liefermethode ungültig') if sale.invoice_method != 'shipment': raise UserError('Rechnungmethode ungültig') if not sale.payment_term: raise UserError('Keine Zahlungsbedingungen angegeben!') # first check if we have a line without product and issue a warning warning_name = 'saleline_noproduct,%s' % cls need_fixing = [] for sale in sales: if not sale.party.pn_name or len(sale.party.pn_name.strip()) < 1: raise UserError( 'Verkaufsparteien müssen einen PN Namen zugewiesen haben.') for line in sale.lines: if not line.product: need_fixing.append(line.rec_name) if Warning.check(warning_name): if need_fixing: msg = 'Position ohne Produkt gefunden!!' #msg += '\n'.join(need_fixing) raise UserWarning(warning_name, msg) # check if we already have an order fromt his customer for this date with the same sale_date_extra warning_sale_date_extra = 'sale_date_extra,%s' % cls warn_sale_date = [] for sale in sales: others = Pool().get('sale.sale').search([ ('sale_folder_postfix', '=', sale.sale_folder_postfix), ('party', '=', sale.party), ('sale_date', '=', sale.sale_date), ('number', '!=', sale.number), ]) for s in others: warn_sale_date.append(s.number) if Warning.check(warning_sale_date_extra): if warn_sale_date: msg = 'Verkauf für diesen Kunden mit gleichem Bestelldatum und Bestellordner Zusatz existiert bereits:' msg += '\n'.join(warn_sale_date) raise UserWarning(warning_sale_date_extra, msg) # give the users a warning before actually confirming an order and creating shipments,.. confirm_warning = 'sale_confirm,%s' % cls if Warning.check(confirm_warning): raise UserWarning( confirm_warning, 'Bestätigen des Verkaufs erzeugt einen Lieferschein - fortfahren?' ) super(Sale, cls).confirm(sales)
def post(cls, invoices): pool = Pool() Warning = pool.get('res.user.warning') super(Invoice, cls).post(invoices) differences = [] for invoice in invoices: if invoice.type == 'out' or not invoice.use_edi: continue if not invoice.edi_invoices: continue edi_invoice = invoice.edi_invoices[-1] if edi_invoice.differences_state == 'difference': differences.append(invoice) if differences: key = 'confirm_invoice_with_difference_%s' % ("_".join( [str(x.id) for x in differences])) if Warning.check(key): raise UserWarning( key, gettext( 'account_invoice_edi.confirm_invoice_with_difference', invoices=",".join([x.reference for x in differences]))) cls.generate_edi_file(invoices)
def draft(cls, invoices): pool = Pool() Warning = pool.get('res.user.warning') super(Invoice, cls).draft(invoices) invoices_sii = [] to_write = [] for invoice in invoices: to_write.extend(([invoice], {'sii_pending_sending': False})) if invoice.sii_state: invoices_sii.append('%s: %s' % ( invoice.number, invoice.sii_state)) for record in invoice.sii_records: if record.report.state == 'draft': raise UserError(gettext('aeat_sii.invoices_sii_pending')) if invoices_sii: warning_name = 'invoices_sii.' + hashlib.md5( ''.join(invoices_sii).encode('utf-8')).hexdigest() if Warning.check(warning_name): raise UserWarning(warning_name, gettext('aeat_sii.msg_invoices_sii', invoices='\n'.join(invoices_sii))) if to_write: cls.write(*to_write)
def do_renumber(self, action): pool = Pool() Move = pool.get('account.move') Sequence = pool.get('ir.sequence') Warning = pool.get('res.user.warning') draft_moves = Move.search([ ('period.fiscalyear', '=', self.start.fiscalyear.id), ('state', '=', 'draft'), ]) if draft_moves: key = 'move_renumber_draft_moves%s' % self.start.fiscalyear.id if Warning.check(key): raise UserWarning( key, gettext('account_move_renumber.draft_moves_in_fiscalyear', fiscalyear=self.start.fiscalyear.rec_name)) sequences = set([self.start.fiscalyear.post_move_sequence]) for period in self.start.fiscalyear.periods: if period.post_move_sequence: sequences.add(period.post_move_sequence) Sequence.write(list(sequences), { 'number_next': self.start.first_number, }) moves_to_renumber = Move.search([ ('period.fiscalyear', '=', self.start.fiscalyear.id), ('post_number', '!=', None), ], order=[ ('date', 'ASC'), ('id', 'ASC'), ]) move_vals = [] for move in moves_to_renumber: if move == self.start.first_move: number_next_old = move.period.post_move_sequence_used.number_next Sequence.write(list(sequences), { 'number_next': 1, }) move_vals.extend(([move], { 'post_number': Sequence.get_id(move.period.post_move_sequence_used.id), })) Sequence.write(list(sequences), { 'number_next': number_next_old, }) continue move_vals.extend(([move], { 'post_number': (move.period.post_move_sequence_used.get()), })) Move.write(*move_vals) action['pyson_domain'] = PYSONEncoder().encode([ ('period.fiscalyear', '=', self.start.fiscalyear.id), ('post_number', '!=', None), ]) return action, {}
def copy_from(self, from_table): Warning = Pool().get('res.user.warning') fields = {x.name for x in self.fields} from_fields = {x.name for x in from_table.fields} missing = sorted(list(from_fields - fields)) existing = fields & from_fields fields = {} for field in self.fields: if field.name in existing: fields[field.name] = field.type different_types = [] for field in from_table.fields: if field.name in existing: if (FIELD_TYPE_TRYTON[field.type] != FIELD_TYPE_TRYTON[fields[field.name]]): different_types.append( "%s (%s -> %s)" % (field.name, field.type, fields[field.name])) existing.remove(field.name) if missing or different_types: message = ['- %s' % x for x in (missing + different_types)] key = 'shine_copy_from_warning.%s.%s' % (self.name, from_table.id), if Warning.check(key): raise UserWarning( key, gettext('shine.copy_from_warning', fields='\n'.join(message), from_table=from_table.rec_name, table=self.rec_name)) if not existing: return existing = sorted(list(existing)) table = sql.Table(from_table.name) subquery = table.select() subquery.columns = [sql.Column(table, x) for x in existing] table = sql.Table(self.name) query = table.insert([sql.Column(table, x) for x in existing], subquery) cursor = Transaction().connection.cursor() cursor.execute(*query)
def _set_done(cls, todos, finish_date, done_childs): pool = Pool() Warning = pool.get('res.user.warning') to_done = [] for todo in todos: todo.state = 'done' todo.finish_date = finish_date to_done.append(todo) if todo.childs: if not done_childs: msg_id = 'todo_done_childs_' + str(todo.id) if Warning.check(msg_id): raise UserWarning( msg_id, gettext('todo.msg_todo_done_childs', todo=todo.rec_name)) to_done += cls._set_done(todo.childs, finish_date, True) return to_done
def check_diagnosis_length(cls, details): Warning = Pool().get('res.user.warning') for detail in details: if not detail.template or not detail.template.diagnosis_length: continue diagnosis_length = detail.template.diagnosis_length for sample in detail.samples: if not sample.diagnosis: continue if len(sample.diagnosis) > diagnosis_length: key = 'lims_diagnosis_length@%s' % sample.id if Warning.check(key): raise UserWarning( key, gettext( 'lims_diagnosis.msg_invalid_diagnosis_length', length=str(len(sample.diagnosis)), allowed=str(diagnosis_length)))
def generate_edi_file(cls, shipments): pool = Pool() Configuration = pool.get('stock.configuration') Warning = pool.get('res.user.warning') done_edi_shipment = Transaction().context.get( 'done_edi_shipment', False) if done_edi_shipment: configuration = Configuration(1) if not configuration.automatic_edi_shipment_out: return for shipment in shipments: if shipment.is_edi: if done_edi_shipment: warning_name = '%s.send_edi_shipment' % shipment if Warning.check(warning_name): raise UserWarning(warning_name, gettext( 'stock_shipment_out_edi.msg_send_edi_shipment', shipment=shipment.number)) shipment.generate_edi()