From 6cf7419497a7e44963d18355bdbf3eb42cbd6483 Mon Sep 17 00:00:00 2001 From: Ahmed Aly Date: Tue, 3 Jul 2018 08:19:59 +0200 Subject: [PATCH] Fall 234: Versandarten - Webshop --- ext/custom-addons/dp_website/__manifest__.py | 5 ++-- .../dp_website/models/__init__.py | 1 + .../dp_website/models/delivery_carrier.py | 26 +++++++++++++++++++ .../dp_website/models/sale_order.py | 8 ++++++ .../dp_website/security/rule.xml | 11 ++++++++ .../dp_website/views/delivery_carrier.xml | 17 ++++++++++++ setup/lib/functions.py | 2 +- 7 files changed, 67 insertions(+), 3 deletions(-) create mode 100755 ext/custom-addons/dp_website/models/delivery_carrier.py create mode 100755 ext/custom-addons/dp_website/views/delivery_carrier.xml diff --git a/ext/custom-addons/dp_website/__manifest__.py b/ext/custom-addons/dp_website/__manifest__.py index 29eb9a67..e3ff8423 100644 --- a/ext/custom-addons/dp_website/__manifest__.py +++ b/ext/custom-addons/dp_website/__manifest__.py @@ -12,11 +12,12 @@ 'support': 'office@datenpol.at', 'website': 'https://www.datenpol.at', 'depends': [ - 'website', - 'website_multi_theme', + 'delivery', + 'website_sale_delivery', 'website_multi_company_sale', ], 'data': [ + 'views/delivery_carrier.xml', 'security/rule.xml' ], 'installable': True, diff --git a/ext/custom-addons/dp_website/models/__init__.py b/ext/custom-addons/dp_website/models/__init__.py index c0b4257c..585bb3e1 100644 --- a/ext/custom-addons/dp_website/models/__init__.py +++ b/ext/custom-addons/dp_website/models/__init__.py @@ -1,2 +1,3 @@ from . import sale_order from . import stock_picking +from . import delivery_carrier diff --git a/ext/custom-addons/dp_website/models/delivery_carrier.py b/ext/custom-addons/dp_website/models/delivery_carrier.py new file mode 100755 index 00000000..ae541232 --- /dev/null +++ b/ext/custom-addons/dp_website/models/delivery_carrier.py @@ -0,0 +1,26 @@ +# 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 + + +class DeliveryCarrier(models.Model): + _inherit = 'delivery.carrier' + + website_ids = fields.Many2many('website', string='Allowed websites', + help='Set the websites this delivery carrier should be available on. ' + 'Leave empty to allow all.') + + @api.onchange('company_id') + def _onchange_company_id(self): + return self.company_id and {'domain': {'website_ids': [('company_id', '=', self.company_id.id)]}} or { + 'domain': {'website_ids': []}} + + @api.constrains('company_id', 'website_ids') + def _check_websites_in_company(self): + for record in self: + website_company = record.website_ids.mapped('company_id') + if record.company_id and record.website_ids and ( + len(website_company) > 1 or website_company[0] != record.company_id): + raise ValidationError(_("Error! Only the company's websites are allowed")) diff --git a/ext/custom-addons/dp_website/models/sale_order.py b/ext/custom-addons/dp_website/models/sale_order.py index 3a86a05e..68bf6fe4 100755 --- a/ext/custom-addons/dp_website/models/sale_order.py +++ b/ext/custom-addons/dp_website/models/sale_order.py @@ -16,3 +16,11 @@ class SaleOrder(models.Model): sale_template.send_mail(self.id) return result + + def _get_delivery_methods(self): + address = self.partner_shipping_id + return self.env['delivery.carrier'].sudo().search([ + ('website_published', '=', True), '|', + ('website_ids', '=', False), + ('website_ids', 'in', [self.env.context.get('website_id', False)]), + ]).available_carriers(address) diff --git a/ext/custom-addons/dp_website/security/rule.xml b/ext/custom-addons/dp_website/security/rule.xml index 75fda9fb..8eb9fcea 100644 --- a/ext/custom-addons/dp_website/security/rule.xml +++ b/ext/custom-addons/dp_website/security/rule.xml @@ -1,3 +1,7 @@ + + + true @@ -5,4 +9,11 @@ true + + + Delivery Carrier available only for specifed websites (shops) + + ['|', ('website_ids', 'in', [website_id]), ('website_ids', '=', False)] + true + diff --git a/ext/custom-addons/dp_website/views/delivery_carrier.xml b/ext/custom-addons/dp_website/views/delivery_carrier.xml new file mode 100755 index 00000000..f75284a9 --- /dev/null +++ b/ext/custom-addons/dp_website/views/delivery_carrier.xml @@ -0,0 +1,17 @@ + + + + + + delivery_carrier_from_view + delivery.carrier + + + + + + + + diff --git a/setup/lib/functions.py b/setup/lib/functions.py index f81a3cca..29bf3935 100644 --- a/setup/lib/functions.py +++ b/setup/lib/functions.py @@ -332,7 +332,7 @@ class DatenpolFunctions(object): 'module': 'dp_website', 'name': 'tz_heizpaneele', 'res_id': str(heizpaneele), - 'noupdate': False, + 'noupdate': True, } ir_model_obj.create(vals) else: