From 92aa4c7d8ad1b1ef327a7fb7e94d565ed459325a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Br=C3=BCckl?= Date: Mon, 11 Jun 2018 17:00:18 +0200 Subject: [PATCH] FB1776: SST-02 Fehler anzeigen, Partner korrekt markieren --- ext/custom-addons/dp_custom/models/product.py | 26 +++++++++---------- .../dp_custom/models/res_partner.py | 17 +++++++----- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/ext/custom-addons/dp_custom/models/product.py b/ext/custom-addons/dp_custom/models/product.py index 3f10d981..ed1b0ec0 100644 --- a/ext/custom-addons/dp_custom/models/product.py +++ b/ext/custom-addons/dp_custom/models/product.py @@ -22,7 +22,7 @@ from odoo.addons.component.core import Component from odoo import fields, models, api, _ from odoo.exceptions import ValidationError - +from odoo.addons.queue_job.job import job class ProductXCategory(models.Model): _name = 'product.xcategory' @@ -152,24 +152,15 @@ class ProductPricelistItemEventListener(Component): @api.model def on_record_write(self, record, fields=None): - partners = self.env['res.partner'].search([('property_product_pricelist', '=', record.pricelist_id.id)]) - for partner in partners: - if partner.portal_id and partner.company_type == 'company': - partner.portal_export_pending = True + self.env['product.pricelist.item'].with_delay().job_mark_partner_for_export(record.pricelist_id.id) @api.model def on_record_create(self, record, fields=None): - partners = self.env['res.partner'].search([('property_product_pricelist', '=', record.pricelist_id.id)]) - for partner in partners: - if partner.portal_id and partner.company_type == 'company': - partner.portal_export_pending = True + self.env['product.pricelist.item'].with_delay().job_mark_partner_for_export(record.pricelist_id.id) @api.model def on_record_unlink(self, record): - partners = self.env['res.partner'].search([('property_product_pricelist', '=', record.pricelist_id.id)]) - for partner in partners: - if partner.portal_id and partner.company_type == 'company': - partner.portal_export_pending = True + self.env['product.pricelist.item'].with_delay().job_mark_partner_for_export(record.pricelist_id.id) class ProductPricelistItem(models.Model): @@ -179,3 +170,12 @@ class ProductPricelistItem(models.Model): ('3_global', 'Global'), ('2_product_category', ' Product Category'), ('0_product_variant', 'Product Variant')]) + + @api.multi + @job + def job_mark_partner_for_export(self, pricelist_id): + partners = self.env['res.partner'].search([('company_type','=','company'),('portal_id','!=',False)]) + for partner in partners: + # Search ist auf die Preisliste nicht möglich, daher wird jeder Partner einzeln verglichen + if partner.property_product_pricelist.id == pricelist_id: + partner.portal_export_pending = True \ No newline at end of file diff --git a/ext/custom-addons/dp_custom/models/res_partner.py b/ext/custom-addons/dp_custom/models/res_partner.py index 86b442f6..7586937e 100644 --- a/ext/custom-addons/dp_custom/models/res_partner.py +++ b/ext/custom-addons/dp_custom/models/res_partner.py @@ -319,13 +319,16 @@ class Partner(models.Model): 'code': code, 'discount': 1 - (item.percent_price / 100) }) - portal_url = tools.config.get('portal_url') - application_id = tools.config.get('portal_secret') - response = requests.post(portal_url + '/api/v1/set-discounts/?secret=' + application_id, - data=json.dumps(data)) - if response.status_code != 200: - raise ValidationError(_('Rabatt konnte nicht gesetzt werden. ' - 'Status Code: %s, Reason: %s') % (response.status_code, response.reason)) + if data: + portal_url = tools.config.get('portal_url') + application_id = tools.config.get('portal_secret') + response = requests.post(portal_url + '/api/v1/set-discounts/?secret=' + application_id, + data=json.dumps(data)) + if response.status_code != 200: + data = response.json() + error_string = data.get('errors',[]) + raise ValidationError(_('Rabatt konnte nicht gesetzt werden. ' + 'Status Code: %s, Reason: %s') % (response.status_code, error_string)) @api.multi def write(self, vals):