def get(self, id): from services.mailinvoice import MailInvoiceService mail = MailInvoiceService.get_mail(id) MailInvoiceService.handle(mail) db.session.add(mail) db.session.commit() return mail
def handle_invoice(self, datetime, file_name, mail_id): mail_stub = self.get_stub(datetime, file_name) MailHepls.get_mails = Mock(return_value=( ProviderTestSuite.EMAIL, {ProviderTestSuite.EMAIL: [mail_stub]})) MailInvoiceService.get_count_new_mails = Mock(return_value=1) MailInvoiceService.handle_mail() resp = self.client.post( "/api/mail/" + str(mail_id), data=self._serialize({ 'action': 'R', 'index': 0 }), headers=self._get_headers(True)) return resp
def get(self, mail_id): from services.mailinvoice import MailInvoiceService try: mail = MailInvoiceService.get_mail(mail_id) invoice = mail.invoice return _stub(invoice) except Exception as exc: error(unicode(exc)) raise
def post(self): """ Запрос на обработку почтового ящика(проверка новых писем и сохранение их в БД). """ from services.mailinvoice import MailInvoiceService, \ MailInvoiceException try: res = MailInvoiceService.handle_mail() except MailInvoiceException as err: error(unicode(err)) abort(400, message=unicode(err)) res = 'ok' if len(res) else 'nothing' return res
def post(self, id): from services.mailinvoice import MailInvoiceService action = request.json['action'] index = request.json['index'] debug(u"Обработка файла почты под индексом '%s' по типу '%s'" % ( index, action)) mail = MailInvoiceService.get_mail(id) file = mail.get_file_to_index(index) fpth = file['path'] debug(u"Путь к файлу - '%s'" % fpth) if action == "R": if mail.invoice_id: debug(u"Файл уже был обработан.") return mail try: debug(u"Обработка файла.") m = InvoiceModel(fpth) m.handle(mail.provider, mail) mail.is_handling = True db.session.add(mail) db.session.commit() debug(u"Обработка файла завершена.") except Exception as err: error( u"Ошибка при обработке файла '"+fpth+u"'. " + unicode(err)) abort(400, message=u"Произошла ошибка в обработке документа.") else: return mail elif action == "V": if mail.return_id: debug(u"Файл уже был обработан.") return mail try: debug(u"Обработка файла.") m = InvoiceReturnModel(fpth) m.handle(mail.provider, mail) mail.is_handling = True db.session.add(mail) db.session.commit() debug(u"Обработка файла завершена.") except Exception as err: error( u"Ошибка при обработке файла '"+fpth+u"'. " + unicode(err)) abort(400, message=u"Произошла ошибка в обработке документа.") else: return mail
def post(self): data = request.json['data'] prices = data['items'] invoice_id = data['invoice_id'] mail = MailInvoiceService.get_mail(invoice_id) invoice = mail.invoice try: PriceService.create_or_update_prices(invoice, prices) mail.is_handling = True db.session.add(mail) db.session.commit() except PriceServiceException as err: debug(unicode(err)) abort(404, message=unicode(err)) except Exception as exc: error(unicode(exc)) raise return "ok"
def get(self, id): from services.mailinvoice import MailInvoiceService mail = MailInvoiceService.get_mail(id) return InvoiceItemResource().get(mail.invoice_id)