SST-02a send pricelist, send partner-pricelistinformation
parent
d6ead5146c
commit
1471ff2cf2
|
|
@ -18,12 +18,26 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import json
|
||||
|
||||
import requests
|
||||
|
||||
from odoo.addons.component.core import Component
|
||||
|
||||
from odoo import fields, models, api, _
|
||||
from odoo import tools, fields, models, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.addons.queue_job.job import job
|
||||
|
||||
import ssl
|
||||
try:
|
||||
_create_unverified_https_context = ssl._create_unverified_context
|
||||
except AttributeError:
|
||||
# Legacy Python that doesn't verify HTTPS certificates by default
|
||||
pass
|
||||
else:
|
||||
# Handle target environment that doesn't support HTTPS verification
|
||||
ssl._create_default_https_context = _create_unverified_https_context
|
||||
|
||||
|
||||
class ProductXCategory(models.Model):
|
||||
_name = 'product.xcategory'
|
||||
|
|
@ -163,18 +177,34 @@ class ProductPricelistItemEventListener(Component):
|
|||
_inherit = 'base.event.listener'
|
||||
_apply_on = ['product.pricelist.item']
|
||||
|
||||
# pricelist_mode = 'partner'
|
||||
|
||||
@api.model
|
||||
def on_record_write(self, record, fields=None):
|
||||
self.env['product.pricelist.item'].with_delay().job_mark_partner_for_export(record.pricelist_id.id)
|
||||
pricelist_mode = self.env['ir.config_parameter'].sudo().get_param('pricelist_mode')
|
||||
if pricelist_mode == 'partner':
|
||||
self.env['product.pricelist.item'].with_delay().job_mark_partner_for_export(record.pricelist_id.id)
|
||||
else:
|
||||
# self.env['product.pricelist.item'].with_delay().job_export_portal_pricelist(record.pricelist_id.id)
|
||||
self.env['product.pricelist.item'].job_export_portal_pricelist(record.pricelist_id.id)
|
||||
|
||||
@api.model
|
||||
def on_record_create(self, record, fields=None):
|
||||
self.env['product.pricelist.item'].with_delay().job_mark_partner_for_export(record.pricelist_id.id)
|
||||
pricelist_mode = self.env['ir.config_parameter'].sudo().get_param('pricelist_mode')
|
||||
if pricelist_mode == 'partner':
|
||||
self.env['product.pricelist.item'].with_delay().job_mark_partner_for_export(record.pricelist_id.id)
|
||||
else:
|
||||
# self.env['product.pricelist.item'].with_delay().job_export_portal_pricelist(record.pricelist_id.id)
|
||||
self.env['product.pricelist.item'].job_export_portal_pricelist(record.pricelist_id.id)
|
||||
|
||||
@api.model
|
||||
def on_record_unlink(self, record):
|
||||
self.env['product.pricelist.item'].with_delay().job_mark_partner_for_export(record.pricelist_id.id)
|
||||
|
||||
pricelist_mode = self.env['ir.config_parameter'].sudo().get_param('pricelist_mode')
|
||||
if pricelist_mode == 'partner':
|
||||
self.env['product.pricelist.item'].with_delay().job_mark_partner_for_export(record.pricelist_id.id)
|
||||
else:
|
||||
# self.env['product.pricelist.item'].with_delay().job_export_portal_pricelist(record.pricelist_id.id)
|
||||
self.env['product.pricelist.item'].job_export_portal_pricelist(record.pricelist_id.id)
|
||||
|
||||
class ProductPricelistItem(models.Model):
|
||||
_inherit = 'product.pricelist.item'
|
||||
|
|
@ -196,3 +226,46 @@ class ProductPricelistItem(models.Model):
|
|||
todo_partner.write({
|
||||
'portal_export_pending': True
|
||||
})
|
||||
|
||||
@api.multi
|
||||
@job
|
||||
def job_export_portal_pricelist(self, pricelist_id):
|
||||
"""
|
||||
SST-02a
|
||||
:param pricelist_id:
|
||||
:return:
|
||||
"""
|
||||
|
||||
pricelist = self.env['product.pricelist'].search([('id', '=', pricelist_id)])
|
||||
data_pos = []
|
||||
|
||||
for item in pricelist.item_ids:
|
||||
if item.compute_price == 'percentage' and item.applied_on in ['3_global', '2_product_category',
|
||||
'0_product_variant']:
|
||||
code = False
|
||||
if item.applied_on == '2_product_category':
|
||||
code = item.categ_id.code
|
||||
if item.applied_on == '0_product_variant':
|
||||
code = item.product_id.product_tmpl_id.default_code
|
||||
data_pos.append({
|
||||
'code': code,
|
||||
'name': item.name,
|
||||
'discount': 1 - (item.percent_price / 100)
|
||||
})
|
||||
|
||||
if data_pos:
|
||||
|
||||
data = {'pricelist_id': pricelist.id,
|
||||
'pricelist_name': pricelist.name,
|
||||
'items': data_pos}
|
||||
|
||||
portal_url = tools.config.get('portal_url')
|
||||
application_id = tools.config.get('portal_secret')
|
||||
response = requests.post(portal_url + '/api/v1/update-pricelist/?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))
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ from dateutil.relativedelta import relativedelta
|
|||
import dateutil.parser
|
||||
import datetime
|
||||
|
||||
import ssl
|
||||
|
||||
try:
|
||||
import stdnum.eu.vat as stdnum_vat
|
||||
except ImportError:
|
||||
|
|
@ -43,12 +45,19 @@ class PartnerEventListener(Component):
|
|||
def on_record_write(self, record, fields=None):
|
||||
if record.active and record.portal_id and record.company_type == 'company':
|
||||
if 'company_type' in fields or 'property_product_pricelist' in fields:
|
||||
self.env['res.partner'].with_delay().job_export_portal_price(record)
|
||||
pricelist_mode = self.env['ir.config_parameter'].sudo().get_param('pricelist_mode')
|
||||
if pricelist_mode == 'partner':
|
||||
self.env['res.partner'].with_delay().job_export_portal_price(record)
|
||||
else:
|
||||
self.env['res.partner'].export_portal_partner_pricelist(record)
|
||||
|
||||
def on_record_create(self, record, fields=None):
|
||||
if record.active and record.portal_id and record.company_type == 'company':
|
||||
self.env['res.partner'].with_delay().job_export_portal_price(record)
|
||||
|
||||
pricelist_mode = self.env['ir.config_parameter'].sudo().get_param('pricelist_mode')
|
||||
if pricelist_mode == 'partner':
|
||||
self.env['res.partner'].with_delay().job_export_portal_price(record)
|
||||
else:
|
||||
self.env['res.partner'].export_portal_partner_pricelist(record)
|
||||
|
||||
class Partner(models.Model):
|
||||
_name = 'res.partner'
|
||||
|
|
@ -375,8 +384,13 @@ class Partner(models.Model):
|
|||
"""
|
||||
partners = self.search([('portal_export_pending', '=', True), ('company_id', '=', self.env.user.company_id.id)])
|
||||
for partner in partners:
|
||||
self.with_delay().job_export_portal_price(partner)
|
||||
# self.job_export_portal_price(partner)
|
||||
pricelist_mode = self.env['ir.config_parameter'].sudo().get_param('pricelist_mode')
|
||||
if pricelist_mode == 'partner':
|
||||
self.with_delay().job_export_portal_price(partner)
|
||||
# self.job_export_portal_price(partner)
|
||||
else:
|
||||
self.export_portal_partner_pricelist(partner)
|
||||
|
||||
partner.portal_export_pending = False
|
||||
|
||||
@api.multi
|
||||
|
|
@ -415,6 +429,45 @@ class Partner(models.Model):
|
|||
raise ValidationError(_('Rabatt konnte nicht gesetzt werden. '
|
||||
'Status Code: %s, Reason: %s') % (response.status_code, error_string))
|
||||
|
||||
@api.multi
|
||||
def export_portal_partner_pricelist(self, partner_id):
|
||||
"""
|
||||
SST-02a
|
||||
:param partner_id:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
_create_unverified_https_context = ssl._create_unverified_context
|
||||
except AttributeError:
|
||||
# Legacy Python that doesn't verify HTTPS certificates by default
|
||||
pass
|
||||
else:
|
||||
# Handle target environment that doesn't support HTTPS verification
|
||||
ssl._create_default_https_context = _create_unverified_https_context
|
||||
|
||||
if not partner_id.portal_id:
|
||||
raise ValidationError(_("Der Partner mit der ID %s hat keine Portal-ID") % partner_id.id)
|
||||
|
||||
pricelist = partner_id.property_product_pricelist
|
||||
data = {
|
||||
'customer_id': partner_id.commercial_partner_id.portal_id,
|
||||
'pricelist_id': pricelist.id,
|
||||
'pricelist_name': pricelist.name,
|
||||
}
|
||||
|
||||
portal_url = tools.config.get('portal_url')
|
||||
application_id = tools.config.get('portal_secret')
|
||||
response = requests.post(portal_url + '/api/v1/set-pricelist/?secret=' + application_id,
|
||||
data=json.dumps(data))
|
||||
if response.status_code != 200:
|
||||
if response.status_code == 428:
|
||||
self.env['product.pricelist.item'].job_export_portal_pricelist(pricelist.id)
|
||||
else:
|
||||
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):
|
||||
fields_to_check = ['ref', 'portal_id']
|
||||
|
|
|
|||
Loading…
Reference in New Issue