Browse Source

Sales exception checked after Order is confirmed

pull/775/head
Atchuthan, Sodexis 9 years ago
parent
commit
0e02dbdd62
  1. 1
      __openerp__.py
  2. 5
      data/sale.exception.csv
  3. 20
      data/sale_exception_data.xml
  4. 28
      models/sale.py
  5. 3
      views/sale_view.xml
  6. 2
      wizard/sale_exception_confirm.py

1
__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',
],

5
data/sale.exception.csv

@ -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

20
data/sale_exception_data.xml

@ -15,5 +15,25 @@
<field eval="'()'" name="args"/>
</record>
<record id ="excep_no_zip" model="sale.exception">
<field name="name">No ZIP code on destination</field>
<field name="description">No ZIP code on destination</field>
<field name="sequence">50</field>
<field name="model">sale.order</field>
<field name="code">if not order.partner_shipping_id.zip:
failed=True</field>
<field name="active" eval="False"/>
</record>
<record id ="excep_no_stock" model="sale.exception">
<field name="name">Not Enough Virtual Stock</field>
<field name="description">Not Enough Virtual Stock</field>
<field name="sequence">50</field>
<field name="model">sale.order.line</field>
<field name="code">if line.product_id and line.product_id.type == 'product' and line.product_id.virtual_available &lt; line.product_uom_qty:
failed=True</field>
<field name="active" eval="False"/>
</record>
</data>
</openerp>

28
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)

3
views/sale_view.xml

@ -66,6 +66,9 @@
attrs="{'invisible':[('main_exception_id','=', False)]}"/>
</group>
</field>
<xpath expr="//field[@name='date_order']/.." position="inside">
<field name="ignore_exception" states="sale" />
</xpath>
<xpath expr="//group[@name='sales_person']/.."
position="inside">
<newline />

2
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'}
Loading…
Cancel
Save