From fdf556a8d86d49dc7edef12b003435dd0539aad0 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Fri, 30 Mar 2018 17:27:40 +0200 Subject: [PATCH] Fonction de facturation --- golem_resource_pack_account/__manifest__.py | 4 +- .../models/golem_resource_pack.py | 37 +++++++++++++++++-- .../views/golem_resource_pack_views.xml | 16 +++++++- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/golem_resource_pack_account/__manifest__.py b/golem_resource_pack_account/__manifest__.py index 3fc337f..05c4042 100644 --- a/golem_resource_pack_account/__manifest__.py +++ b/golem_resource_pack_account/__manifest__.py @@ -20,13 +20,13 @@ 'name': 'GOLEM resources pack invoicing', 'summary': 'GOLEM resources pack invoicing', 'description': ''' GOLEM resources pack invoicing ''', - 'version': '10.0.0.0.0', + 'version': '10.0.0.0.1', 'category': 'GOLEM', 'author': 'Youssef El Ouahby, Fabien Bourgeois', 'license': 'AGPL-3', 'application': True, 'installable': True, - 'depends': ['golem_resource_pack', 'account'], + 'depends': ['golem_resource_pack', 'golem_resource_account'], 'data': ['views/golem_resource_pack_views.xml'] #'security/ir.model.access.csv'] } diff --git a/golem_resource_pack_account/models/golem_resource_pack.py b/golem_resource_pack_account/models/golem_resource_pack.py index d6c411c..fc80578 100644 --- a/golem_resource_pack_account/models/golem_resource_pack.py +++ b/golem_resource_pack_account/models/golem_resource_pack.py @@ -32,13 +32,42 @@ class GolemResourcePack(models.Model): copy=False) invoice_amount_total = fields.Monetary(related='invoice_id.amount_total') currency_id = fields.Many2one(related='invoice_id.currency_id') + is_products_set = fields.Boolean(compute="compute_is_products_set") + + @api.multi + def compute_is_products_set(self): + for pack in self: + product_list = list(map(lambda x: x.resource_product_id, pack.reservation_ids)) + if len(filter(lambda x: x.id == False, product_list)) > 0: + pack.is_products_set = False + else: + pack.is_products_set = True @api.multi def create_invoice(self): - """ create invoice """ - pass + """ Invoice creation """ + for pack in self: + pack.reservation_ids.check_before_invoicing() + inv_obj = self.env['account.invoice'] + partner_id = pack.partner_id + invoice_id = inv_obj.create({ + 'origin': pack.name, + 'type': 'out_invoice', + 'reference': False, + 'account_id': partner_id.property_account_receivable_id.id, + 'partner_id': partner_id.id + }) + pack.invoice_id = invoice_id.id + pack.reservation_ids.create_invoice_line(invoice_id) @api.multi def show_invoice(self): - """ show invoice """ - pass + """ Redirects to linked invoice """ + self.ensure_one() + pack = self[0] + if pack.invoice_id: + return {'type': 'ir.actions.act_window', + 'res_model': 'account.invoice', + 'res_id': pack.invoice_id.id, + 'view_mode': 'form', + 'view_id': self.env.ref('account.invoice_form').id} diff --git a/golem_resource_pack_account/views/golem_resource_pack_views.xml b/golem_resource_pack_account/views/golem_resource_pack_views.xml index 7fc88f3..6d37fcd 100644 --- a/golem_resource_pack_account/views/golem_resource_pack_views.xml +++ b/golem_resource_pack_account/views/golem_resource_pack_views.xml @@ -18,21 +18,33 @@ along with this program. If not, see . --> + + + GOLEM Resource Pack Account extention Tree + golem.resource.pack + + + + + + + - GOLEM Resource Pack Account extentionForm + GOLEM Resource Pack Account extention Form golem.resource.pack +