[IMP]GOLEM Resource Account : do not allow invoice creation without product, improve creation algorithm

This commit is contained in:
Fabien BOURGEOIS 2018-03-26 11:11:16 +02:00
parent 1957dd8ca2
commit ba7ab02084

View File

@ -20,7 +20,7 @@
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from odoo.exceptions import UserError from odoo.exceptions import ValidationError
class GolemResourceReservation(models.Model): class GolemResourceReservation(models.Model):
@ -41,19 +41,19 @@ class GolemResourceReservation(models.Model):
product = reservation.resource_id.product_tmpl_id product = reservation.resource_id.product_tmpl_id
amount = product.standard_price amount = product.standard_price
if product.id: if not product:
account_id = product.property_account_income_id.id raise ValidationError(_('You can not create an invoice without '
'linked product on the resource reserved.'))
account_id = product.property_account_income_id.id or \
product.categ_id.property_account_income_categ_id.id
if not account_id: if not account_id:
account_id = product.categ_id.property_account_income_categ_id.id raise ValidationError(
if not account_id:
raise UserError(
_('There is no income account defined for this product: "%s". \ _('There is no income account defined for this product: "%s". \
You may have to install a chart of account from Accounting \ You may have to install a chart of account from Accounting \
app, settings menu.') % (product.name,)) app, settings menu.') % (product.name,))
reservation.invoice_id = inv_obj.create({ reservation.invoice_id = inv_obj.create({
'name': reservation.name, 'name': reservation.name,
#'origin': self.application_number, #'origin': self.application_number,