forked from Yaltik/golem
[REF]GOLEM Resource Account : separate check, create invoice and create invoice line actions
This commit is contained in:
parent
7c4bc395a3
commit
2336614701
@ -18,7 +18,6 @@
|
||||
|
||||
""" GOLEM Resource Reservation Adaptation"""
|
||||
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
@ -37,16 +36,13 @@ class GolemResourceReservation(models.Model):
|
||||
currency_id = fields.Many2one(related='invoice_id.currency_id')
|
||||
|
||||
@api.multi
|
||||
def create_invoice(self):
|
||||
""" Invoice creation """
|
||||
def check_before_invoicing(self):
|
||||
""" Checks data coherence before invoicing """
|
||||
for reservation in self:
|
||||
if reservation.invoice_line_id:
|
||||
raise ValidationError(_('You can not create an invoice as there '
|
||||
'is already one.'))
|
||||
inv_obj = self.env['account.invoice']
|
||||
partner_id = reservation.partner_id
|
||||
product = reservation.resource_id.product_tmpl_id
|
||||
amount = product.list_price
|
||||
|
||||
if not product:
|
||||
raise ValidationError(_('You can not create an invoice without '
|
||||
@ -60,23 +56,43 @@ class GolemResourceReservation(models.Model):
|
||||
_('There is no income account defined for this product: "{}"'
|
||||
'. You have to configure it on the product form.'.format(product.name)))
|
||||
|
||||
reservation.invoice_id = inv_obj.create({
|
||||
@api.multi
|
||||
def create_invoice_line(self, invoice_id):
|
||||
""" Create invoice line corresponding to reservation """
|
||||
for reservation in self:
|
||||
product = reservation.resource_id.product_tmpl_id
|
||||
amount = product.list_price
|
||||
account_id = product.property_account_income_id.id or \
|
||||
product.categ_id.property_account_income_categ_id.id
|
||||
|
||||
line_id = self.env['account.invoice.line'].create({
|
||||
'invoice_id': invoice_id.id,
|
||||
'name': product.name,
|
||||
'origin': reservation.name,
|
||||
'price_unit': amount,
|
||||
'quantity': 1.0,
|
||||
'uom_id': product.uom_id.id,
|
||||
'account_id': account_id,
|
||||
'product_id': product.id,
|
||||
})
|
||||
reservation.invoice_line_id = line_id
|
||||
|
||||
@api.multi
|
||||
def create_invoice(self):
|
||||
""" Invoice creation """
|
||||
for reservation in self:
|
||||
reservation.check_before_invoicing()
|
||||
inv_obj = self.env['account.invoice']
|
||||
partner_id = reservation.partner_id
|
||||
|
||||
invoice_id = inv_obj.create({
|
||||
'origin': reservation.name,
|
||||
'type': 'out_invoice',
|
||||
'reference': False,
|
||||
'account_id': partner_id.property_account_receivable_id.id,
|
||||
'partner_id': partner_id.id,
|
||||
'invoice_line_ids': [(0, 0, {
|
||||
'name': reservation.resource_id.name,
|
||||
'origin': reservation.name,
|
||||
'price_unit': amount,
|
||||
'quantity': 1.0,
|
||||
'uom_id': product.uom_id.id,
|
||||
'account_id': account_id,
|
||||
'product_id': product.id,
|
||||
})]
|
||||
'partner_id': partner_id.id
|
||||
})
|
||||
reservation.invoice_line_id = reservation.invoice_id.invoice_line_ids[0]
|
||||
reservation.create_invoice_line(invoice_id)
|
||||
|
||||
@api.multi
|
||||
def show_invoice(self):
|
||||
|
Loading…
Reference in New Issue
Block a user