[FIX] sale: raise error if no order found

When creating a SO line, make sure we found an appropriate SO.
This commit is contained in:
Nicolas Martinelli
2015-09-20 20:36:21 +02:00
parent 198164dd04
commit 59a2e876b7
2 changed files with 10 additions and 2 deletions
+6 -1
View File
@@ -931,6 +931,12 @@ msgstr ""
msgid "No incoterm on reports"
msgstr ""
#. module: sale
#: code:addons/sale/sale_analytic.py:50
#, python-format
msgid "No valid Sale Order was found. Make sure that at least one Sale Order in state \"Sale\" is linked to the specified contract."
msgstr ""
#. module: sale
#: selection:sale.config.settings,group_product_variant:0
msgid "No variants on products"
@@ -1787,4 +1793,3 @@ msgstr ""
#: model:ir.model.fields,field_description:sale.field_sale_config_settings_sale_pricelist_setting
msgid "unknown"
msgstr ""
+4 -1
View File
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from openerp import api, fields, models
from openerp import api, fields, models, _
from openerp.exceptions import UserError
class SaleOrderLine(models.Model):
@@ -45,6 +46,8 @@ class AccountAnalyticLine(models.Model):
def _get_sale_order_line_vals(self):
order = self.env['sale.order'].search([('project_id', '=', self.account_id.id), ('state', '=', 'sale')], limit=1)
if not order:
raise UserError(_('No valid Sale Order was found. Make sure that at least one Sale Order in state "Sale" is linked to the specified contract.'))
last_so_line = self.env['sale.order.line'].search([('order_id', '=', order.id)], order='sequence desc', limit=1)
last_sequence = last_so_line.sequence + 1 if last_so_line else 100