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