diff --git a/product_wise_shipping_method/__manifest__.py b/product_wise_shipping_method/__manifest__.py index 942b69ee2..58b4f3389 100644 --- a/product_wise_shipping_method/__manifest__.py +++ b/product_wise_shipping_method/__manifest__.py @@ -24,11 +24,12 @@ 'version': '16.0.1.0.0', 'category': 'Sales/Sales', 'summary': """ Product Wise Shipping Method for sale order. """, - 'description': """ This module helps to provide shipping method easily via choosing products in order line. """, + 'description': """ This module helps to provide shipping method easily via + choosing products in order line. """, 'author': 'Cybrosys Techno Solutions', 'company': 'Cybrosys Techno Solutions', 'maintainer': 'Cybrosys Techno Solutions', - 'depends': ['base', 'sale','delivery'], + 'depends': ['base', 'sale', 'delivery', 'website_sale'], 'website': 'https://www.cybrosys.com', 'data': [ 'views/product_template_views.xml', diff --git a/product_wise_shipping_method/models/product_template.py b/product_wise_shipping_method/models/product_template.py index 21773057c..165536d56 100644 --- a/product_wise_shipping_method/models/product_template.py +++ b/product_wise_shipping_method/models/product_template.py @@ -23,7 +23,9 @@ from odoo import fields, models class ProductTemplate(models.Model): - """ Inherit product,so we are adding a field for defining shipping method. """ + """Inherit product,so we are adding a field for defining shipping method.""" _inherit = 'product.template' - shipping_method_id = fields.Many2one('delivery.carrier', string='Shipping Method',help="Choose shipping method") + shipping_method_id = fields.Many2one('delivery.carrier', + string='Shipping Method', + help="Choose shipping method.") diff --git a/product_wise_shipping_method/models/sale_order.py b/product_wise_shipping_method/models/sale_order.py index 2bb265cc0..f0a72f95a 100644 --- a/product_wise_shipping_method/models/sale_order.py +++ b/product_wise_shipping_method/models/sale_order.py @@ -25,11 +25,15 @@ from odoo.exceptions import UserError class SaleOrder(models.Model): - """ Inherit sale,so we are getting shipping method corresponding to product""" + """ Inherit sale,so we are getting shipping method corresponding to + product.""" _inherit = 'sale.order' def action_confirm(self): - """Create delivery method value for sale order lines with a shipping method.""" + """Create delivery method value for sale order lines with a + shipping method.""" + if self.website_id: + return super().action_confirm() order_lines_with_shipping = self.order_line.filtered(lambda line: line.product_template_id.shipping_method_id) vals_list = [{ 'product_id': line.product_template_id.shipping_method_id.product_id.id, @@ -43,25 +47,29 @@ class SaleOrder(models.Model): def merge_similar_products(self): """ merge similar products on order line by adding their quantity.""" - similar_products = defaultdict(lambda: {'qty': 0, 'lines_to_remove': []}) + similar_products = defaultdict( + lambda: {'qty': 0, 'lines_to_remove': []}) order_line = self.env['sale.order.line'] for line in self.order_line.sorted(): key = (line.product_id.id, line.price_unit, line.tax_id) similar_products[key]['qty'] += line.product_uom_qty similar_products[key]['lines_to_remove'].append(line.id) for key,product_info in similar_products.items(): - order_line.browse(product_info['lines_to_remove'][0]).write({'product_uom_qty': product_info['qty']}) + order_line.browse(product_info['lines_to_remove'][0]).write( + {'product_uom_qty': product_info['qty']}) order_line.browse(product_info['lines_to_remove'][1:]).unlink() @api.model def create(self, vals): - """ When the products are newly selected in sale order line then they are Create on sale order """ + """ When the products are newly selected in sale order line then they + are Create on sale order """ res = super(SaleOrder, self).create(vals) res.merge_similar_products() return res def write(self, vals): - """ When the products are previously selected then Write similar products on sale order """ + """ When the products are previously selected then Write similar + products on sale order """ res = super(SaleOrder, self).write(vals) self.merge_similar_products() return res