Add wizard for 'reset imos order'
							parent
							
								
									a0bb41dff9
								
							
						
					
					
						commit
						1348885db2
					
				|  | @ -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', | ||||
|  |  | |||
|  | @ -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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -0,0 +1,77 @@ | |||
| # Copyright 2018-Today datenpol gmbh (<http://www.datenpol.at>) | ||||
| # 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 | ||||
|  | @ -0,0 +1,36 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <!-- Copyright 2018-Today datenpol gmbh(<http://www.datenpol.at>) | ||||
|      License OPL-1 or later (https://www.odoo.com/documentation/user/11.0/legal/licenses/licenses.html#licenses). --> | ||||
| 
 | ||||
| <odoo> | ||||
| 
 | ||||
|     <record id="view_wizard_reset_order_form" model="ir.ui.view"> | ||||
|         <field name="name">view_wizard_reset_order_form</field> | ||||
|         <field name="model">wizard.reset_order</field> | ||||
|         <field name="arch" type="xml"> | ||||
|             <form string="Wizard Reset Order"> | ||||
|                 <group> | ||||
|                     <p>Wollen Sie die imos-Bestellung für die markierten Aufträge zurücksetzen?</p> | ||||
|                 </group> | ||||
|                 <footer> | ||||
|                     <button name="button_reset_order" | ||||
|                             string="imos-Bestellung zurücksetzen" | ||||
|                             class="btn-primary" | ||||
|                             type="object"/> | ||||
|                     <button string="Abbrechen" | ||||
|                             class="btn-default" | ||||
|                             special="cancel"/> | ||||
|                 </footer> | ||||
|             </form> | ||||
|         </field> | ||||
|     </record> | ||||
| 
 | ||||
|     <act_window id="action_wizard_reset_order" | ||||
|         name="imos-Bestellung zurücksetzen" | ||||
|         src_model="sale.order" | ||||
|         res_model="wizard.reset_order" | ||||
|         view_type="form" | ||||
|         view_mode="form" | ||||
|         key2="client_action_multi" | ||||
|         target="new"/> | ||||
| </odoo> | ||||
		Loading…
	
		Reference in New Issue