diff --git a/__openerp__.py b/__openerp__.py index a582c2115..0f8ab18c1 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -13,7 +13,6 @@ 'data': [ 'security/ir.model.access.csv', 'wizard/sale_exception_confirm_view.xml', - 'data/sale.exception.csv', 'data/sale_exception_data.xml', 'views/sale_view.xml', ], diff --git a/data/sale.exception.csv b/data/sale.exception.csv deleted file mode 100644 index 84c717ba9..000000000 --- a/data/sale.exception.csv +++ /dev/null @@ -1,5 +0,0 @@ -"id","name","description","sequence","model","code","active" -"excep_no_zip","No ZIP code on destination",,50,"sale.order","if not order.partner_shipping_id.zip: - failed=True",False -"excep_no_stock","Not Enough Virtual Stock",,50,"sale.order.line","if line.product_id and line.product_id.type == 'product' and line.product_id.virtual_available < line.product_uom_qty: - failed=True",False diff --git a/data/sale_exception_data.xml b/data/sale_exception_data.xml index 0b604387a..6db29dcf8 100644 --- a/data/sale_exception_data.xml +++ b/data/sale_exception_data.xml @@ -14,6 +14,26 @@ - + + + No ZIP code on destination + No ZIP code on destination + 50 + sale.order + if not order.partner_shipping_id.zip: + failed=True + + + + + Not Enough Virtual Stock + Not Enough Virtual Stock + 50 + sale.order.line + if line.product_id and line.product_id.type == 'product' and line.product_id.virtual_available < line.product_uom_qty: + failed=True + + + diff --git a/models/sale.py b/models/sale.py index 5e99c800e..669b84c27 100644 --- a/models/sale.py +++ b/models/sale.py @@ -5,7 +5,7 @@ import time from openerp import api, models, fields, _ -from openerp.exceptions import UserError +from openerp.exceptions import UserError, ValidationError from openerp.tools.safe_eval import safe_eval @@ -63,12 +63,12 @@ class SaleOrder(models.Model): 'sale.exception', 'sale_order_exception_rel', 'sale_order_id', 'exception_id', string='Exceptions') - ignore_exceptions = fields.Boolean('Ignore Exceptions', copy=False) + ignore_exception = fields.Boolean('Ignore Exceptions', copy=False) @api.one - @api.depends('state', 'exception_ids') + @api.depends('exception_ids', 'ignore_exception') def _get_main_error(self): - if self.state == 'draft' and self.exception_ids: + if not self.ignore_exception and self.exception_ids: self.main_exception_id = self.exception_ids[0] else: self.main_exception_id = False @@ -91,6 +91,20 @@ class SaleOrder(models.Model): }) return action + @api.one + @api.constrains('ignore_exception', 'order_line', 'state') + def check_sale_exception_constrains(self): + if self.state == 'sale': + exception_ids = self.detect_exceptions() + if exception_ids: + exceptions = self.env['sale.exception'].browse(exception_ids) + raise ValidationError('\n'.join(exceptions.mapped('name'))) + + @api.onchange('order_line') + def onchange_ignore_exception(self): + if self.state == 'sale': + self.ignore_exception = False + @api.multi def action_confirm(self): if self.detect_exceptions(): @@ -101,8 +115,8 @@ class SaleOrder(models.Model): @api.multi def action_cancel(self): for order in self: - if order.ignore_exceptions: - order.ignore_exceptions = False + if order.ignore_exception: + order.ignore_exception = False return super(SaleOrder, self).action_cancel() @api.multi @@ -129,7 +143,7 @@ class SaleOrder(models.Model): all_exception_ids = [] for order in self: - if order.ignore_exceptions: + if order.ignore_exception: continue exception_ids = order._detect_exceptions(order_exceptions, line_exceptions) diff --git a/views/sale_view.xml b/views/sale_view.xml index ace291b11..481dec0ba 100644 --- a/views/sale_view.xml +++ b/views/sale_view.xml @@ -66,6 +66,9 @@ attrs="{'invisible':[('main_exception_id','=', False)]}"/> + + + diff --git a/wizard/sale_exception_confirm.py b/wizard/sale_exception_confirm.py index 856e820bb..facfdbd25 100644 --- a/wizard/sale_exception_confirm.py +++ b/wizard/sale_exception_confirm.py @@ -31,5 +31,5 @@ class SaleExceptionConfirm(models.TransientModel): @api.one def action_confirm(self): if self.ignore: - self.sale_id.ignore_exceptions = True + self.sale_id.ignore_exception = True return {'type': 'ir.actions.act_window_close'}