correction in pg_create_quotation (use prefix for portal_id)
							parent
							
								
									cd4a666466
								
							
						
					
					
						commit
						d169374ea1
					
				|  | @ -234,6 +234,11 @@ class SaleOrder(models.Model): | |||
|         if not vals.get('portal_id', False): | ||||
|             raise ValidationError( | ||||
|                 _("Der Kunde mit der Portal-ID \'%s\' kann nicht zugeordnet werden") % vals['portal_id']) | ||||
| 
 | ||||
|         portal_prefix = self.env.user.company_id.portal_prefix | ||||
|         if portal_prefix: | ||||
|             vals['portal_id'] = portal_prefix + '.' + vals['portal_id'] | ||||
| 
 | ||||
|         partner = self.env['res.partner'].search([('portal_id', '=', vals['portal_id'])]) | ||||
|         if not partner.parent_id: | ||||
|             raise ValidationError( | ||||
|  | @ -318,6 +323,101 @@ class SaleOrder(models.Model): | |||
|             order_id.action_confirm() | ||||
|         return {'id': order_id.id, 'name': order_id.name} | ||||
| 
 | ||||
|         @api.model | ||||
|         def pg_create_quotation___1(self, vals): | ||||
|             """ | ||||
|             SST-3 | ||||
|             :param vals: | ||||
|             :return: | ||||
|             """ | ||||
|             #        print('1') | ||||
|             if not vals.get('portal_id', False): | ||||
|                 raise ValidationError( | ||||
|                     _("Der Kunde mit der Portal-ID \'%s\' kann nicht zugeordnet werden") % vals['portal_id']) | ||||
|             partner = self.env['res.partner'].search([('portal_id', '=', vals['portal_id'])]) | ||||
|             if not partner.parent_id: | ||||
|                 raise ValidationError( | ||||
|                     _('Zu dem Kontakt mit der portal-ID %s existiert kein Unternehmen') % vals['portal_id']) | ||||
|             partner = partner.parent_id | ||||
|             vals['partner_id'] = partner.id | ||||
|             #        print('2') | ||||
|             if not partner: | ||||
|                 raise ValidationError( | ||||
|                     _("Der Kunde mit der Portal-ID \'%s\' kann nicht zugeordnet werden") % vals['portal_id']) | ||||
|             del vals['portal_id'] | ||||
|             delivery_partner = self.env['res.partner'] | ||||
|             delivery_vals = {} | ||||
|             #        print('3') | ||||
|             if vals.get('portal_delivery_id', False): | ||||
|                 delivery_partner = self.env['res.partner'].search([('portal_id', '=', vals['portal_delivery_id'])]) | ||||
|                 delivery_vals['portal_id'] = vals['portal_delivery_id'] | ||||
|                 del vals['portal_delivery_id'] | ||||
|             for key in list(vals.keys()): | ||||
|                 if key.startswith('delivery_'): | ||||
|                     delivery_vals[key.replace('delivery_', '')] = vals[key] | ||||
|                     del vals[key] | ||||
| 
 | ||||
|             #        print('4') | ||||
|             delivery_partner.with_context(delivery_partner=True).check_not_specified_fields(delivery_vals) | ||||
|             delivery_vals = delivery_partner.correct_values(delivery_vals) | ||||
|             delivery_vals['parent_id'] = partner.id | ||||
| 
 | ||||
|             if delivery_partner: | ||||
|                 #            print('4a') | ||||
|                 allowed_update_keys = ['firstname', 'lastname', 'midname', 'email', 'phone'] | ||||
|                 for key in list(delivery_vals.keys()): | ||||
|                     if key not in allowed_update_keys: | ||||
|                         del delivery_vals[key] | ||||
|                 #            print('4a1') | ||||
|                 delivery_partner.write(delivery_vals) | ||||
|             #            print('4a2') | ||||
|             else: | ||||
|                 #            print('4b') | ||||
|                 if not delivery_vals.get('type', False): | ||||
|                     delivery_vals['type'] = 'delivery' | ||||
|                 delivery_vals['property_delivery_carrier_id'] = partner.property_delivery_carrier_id.id | ||||
|                 delivery_partner = delivery_partner.create(delivery_vals) | ||||
| 
 | ||||
|             #        print('5') | ||||
|             attachment_vals = vals.pop('attachment_ids', False) | ||||
|             order_line_vals = vals.get('order_lines', False) | ||||
|             #        if 'attachment_ids' in vals: del vals['attachment_ids'] | ||||
|             del vals['order_lines'] | ||||
|             #        print('6') | ||||
|             self.check_not_specified_fields(vals) | ||||
|             vals = self.correct_values(vals) | ||||
|             payment_term = partner.property_payment_term_id | ||||
|             if partner.retail_partner_id: | ||||
|                 payment_term = partner.retail_partner_id.property_payment_term_id | ||||
|             addr = partner.address_get(['delivery', 'invoice']) | ||||
|             #        print('7') | ||||
|             vals['partner_invoice_id'] = vals.setdefault('partner_invoice_id', addr['invoice']) | ||||
|             partner_invoice_id = self.env['res.partner'].browse([vals['partner_invoice_id']]) | ||||
|             fiscal_position_id = False | ||||
|             #        print('8') | ||||
|             if partner_invoice_id: | ||||
|                 if partner_invoice_id.property_account_position_id: | ||||
|                     fiscal_position_id = partner_invoice_id.property_account_position_id.id | ||||
|             vals.update({ | ||||
|                 'partner_id': partner.id, | ||||
|                 'partner_invoice_id': partner_invoice_id.id, | ||||
|                 'fiscal_position_id': fiscal_position_id, | ||||
|                 'user_id': partner.user_id.id, | ||||
|                 'payment_term_id': payment_term.id, | ||||
|                 'partner_shipping_id': delivery_partner.id, | ||||
|                 'incoterm': partner.sale_incoterm_id.id, | ||||
|                 'carrier_id': delivery_partner.property_delivery_carrier_id.id | ||||
|             }) | ||||
|             #        print('9') | ||||
|             order_id = self.create(vals) | ||||
|             if attachment_vals: | ||||
|                 order_id.pg_create_sale_order_attachments(attachment_vals) | ||||
|             if order_line_vals: | ||||
|                 order_id.pg_create_order_lines(order_line_vals) | ||||
|             if vals.get('confirm_order'): | ||||
|                 order_id.action_confirm() | ||||
|             return {'id': order_id.id, 'name': order_id.name} | ||||
| 
 | ||||
|     @api.multi | ||||
|     def pg_create_sale_order_attachments(self, values): | ||||
|         self.ensure_one() | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue