From 1348885db293a5c950aaa4e9742d9f5ac3547098 Mon Sep 17 00:00:00 2001 From: Andreas Osim Date: Tue, 26 Jun 2018 13:51:48 +0200 Subject: [PATCH] Add wizard for 'reset imos order' --- ext/custom-addons/dp_custom/__manifest__.py | 1 + .../dp_custom/wizards/__init__.py | 2 + .../dp_custom/wizards/wizard_reset_order.py | 77 +++++++++++++++++++ .../dp_custom/wizards/wizard_reset_order.xml | 36 +++++++++ 4 files changed, 116 insertions(+) create mode 100644 ext/custom-addons/dp_custom/wizards/wizard_reset_order.py create mode 100644 ext/custom-addons/dp_custom/wizards/wizard_reset_order.xml diff --git a/ext/custom-addons/dp_custom/__manifest__.py b/ext/custom-addons/dp_custom/__manifest__.py index f906da6d..00ce1b1c 100644 --- a/ext/custom-addons/dp_custom/__manifest__.py +++ b/ext/custom-addons/dp_custom/__manifest__.py @@ -44,6 +44,7 @@ 'views/commission_account.xml', 'wizards/wizard_confirm_production.xml', 'wizards/wizard_import_tzbox.xml', + 'wizards/wizard_reset_order.xml', 'wizards/portal_assign_company.xml', 'wizards/wizard_confirm_print_invoice.xml', 'security/security.xml', diff --git a/ext/custom-addons/dp_custom/wizards/__init__.py b/ext/custom-addons/dp_custom/wizards/__init__.py index ddbef7c2..158afb89 100644 --- a/ext/custom-addons/dp_custom/wizards/__init__.py +++ b/ext/custom-addons/dp_custom/wizards/__init__.py @@ -2,3 +2,5 @@ from . import wizard_confirm_production from . import wizard_import_tzbox from . import wizard_confirm_print_invoice from . import portal_assign_company +from . import wizard_reset_order + diff --git a/ext/custom-addons/dp_custom/wizards/wizard_reset_order.py b/ext/custom-addons/dp_custom/wizards/wizard_reset_order.py new file mode 100644 index 00000000..724f4f47 --- /dev/null +++ b/ext/custom-addons/dp_custom/wizards/wizard_reset_order.py @@ -0,0 +1,77 @@ +# Copyright 2018-Today datenpol gmbh () +# License OPL-1 or later (https://www.odoo.com/documentation/user/11.0/legal/licenses/licenses.html#licenses). + +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError, UserError + +import json +import requests + +class WizardResetOrder(models.TransientModel): + _name = 'wizard.reset_order' + _description = 'Reset imos-Order' + + name = fields.Char() + + @api.multi + def button_reset_order(self): + for wizard in self: + error_at_quotation = False + info = 'Bitte prüfen Sie den Angebotsstatus & Auftragsart folgender Angebote:' + active_ids = self.env.context.get('active_ids', []) + sale_orders = self.env['sale.order'].browse(active_ids) + if sale_orders.exists(): + for so in sale_orders: + if so.state == 'cancel' and so.order_type == 'D': + info += "\n %s -- OK" % so.name + else: + info += "\n %s state='%s',order_type='%s'" % (so.name,so.state,so.order_type) + error_at_quotation = True + if error_at_quotation: + raise ValidationError(_(info)) + + info = 'Mindestens eines der Angebote konnte nicht zurückgesetzt werden:' + for so in sale_orders: + order_info = self.reset_order_status(so.origin) + if order_info != '': + error_at_quotation = True + info += "\n"+order_info + else: + info += "\n%s --> OK" % so.name + + if error_at_quotation: + raise UserError(_(info)) + + action = self.env.ref('sale.action_orders').read()[0] + action['domain'] = [('id', 'in', active_ids)] + return action + + def reset_order_status(self, order_id): + self.ensure_one() +# portal_url = tools.config.get('portal_url') + info = '' + imos_url = r'https://2138.testshop.imos3d.com?id=142&tx_imosnetpublic_api[controller]=Basket&tx_imosnetpublic_api[action]=update' + idata = {"uid" : int(order_id[-6:]), "status" : 0} + data = { + 'pass' : '8io4u39ruhiz378uih', + 'user' : 'publicapiuser', + 'pid' : 5, + 'logintype' : 'login', + 'tx_imosnetpublic_api[data]' : json.dumps(idata) + } + response = requests.post(imos_url, data=data) + + try: + lRes = json.loads(response.content.decode()) + except Exception as e: + info = 'unexpected error %s' % e + raise ValidationError(_(info)) + + if response.status_code == 200: + if lRes.get('status') != 0: + info = "Angebot: %s, Fehler='%s'" % (order_id,lRes) + else: + if lRes.get('status') != 0: + info = "Angebot: %s, Fehler='%s'" % (order_id,lRes.get('data')) + + return info diff --git a/ext/custom-addons/dp_custom/wizards/wizard_reset_order.xml b/ext/custom-addons/dp_custom/wizards/wizard_reset_order.xml new file mode 100644 index 00000000..d1b4537e --- /dev/null +++ b/ext/custom-addons/dp_custom/wizards/wizard_reset_order.xml @@ -0,0 +1,36 @@ + + + + + + + view_wizard_reset_order_form + wizard.reset_order + +
+ +

Wollen Sie die imos-Bestellung für die markierten Aufträge zurücksetzen?

+
+
+
+
+
+
+ + +