From 329830bcf8a8acbbcb2faac6d8adf3b09f7614d1 Mon Sep 17 00:00:00 2001 From: daniquilez <dani.quilez@gmail.com> Date: Thu, 27 Feb 2025 11:27:01 +0100 Subject: [PATCH] =?UTF-8?q?[IMP]=20=E2=9C=A8=20Service=20invoicing=20batch?= =?UTF-8?q?=20creation=20redirects=20to=20contracts=20tree=20view?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/contract.py | 9 ++ energy_communities_service_invoicing/utils.py | 38 +++--- .../views/contract_views.xml | 110 +++++++++--------- .../views/service_invoicing_views.xml | 12 +- .../service_invoicing_action_create.py | 7 +- 5 files changed, 89 insertions(+), 87 deletions(-) diff --git a/energy_communities_service_invoicing/models/contract.py b/energy_communities_service_invoicing/models/contract.py index 14932d2aa..b10170d78 100644 --- a/energy_communities_service_invoicing/models/contract.py +++ b/energy_communities_service_invoicing/models/contract.py @@ -232,6 +232,15 @@ class ContractContract(models.Model): contract.set_close_status_type_by_date() return True + # TODO: It would be very cool being able to use this methods on service_invoicing xml act_window definition + @api.model + def get_service_invoicing_views_domain(self): + return [("community_company_id", "!=", False)] + + @api.model + def get_service_invoicing_views_context(self): + return {"search_default_not_finished": 1, "search_default_paused": 1} + # TODO: Not working. Lack of access rules def _get_received_invoices_ids(self): received_invoices = [] diff --git a/energy_communities_service_invoicing/utils.py b/energy_communities_service_invoicing/utils.py index 15ba8b89a..f24348955 100644 --- a/energy_communities_service_invoicing/utils.py +++ b/energy_communities_service_invoicing/utils.py @@ -22,29 +22,27 @@ _SALE_ORDER_SERVICE_INVOICING_ACTION_VALUES = [ def service_invoicing_tree_view(env: Environment): - # return { - # "type": "ir.actions.act_window", - # "res_model": "contract.contract", - # "views": [ - # ( - # env.ref( - # "energy_communities_service_invoicing.view_service_invoicing_tree" - # ).id, - # "tree", - # ), - # ], - # "target": "current", - # } - return { - # 'name': _('test'), + "name": _("Service Contracts"), "view_type": "tree", - "view_mode": "tree", - "view_id": env.ref( - "energy_communities_service_invoicing.view_service_invoicing_window_platform_manager" - ).id, + "view_mode": "tree,form", + "views": [ + ( + env.ref( + "energy_communities_service_invoicing.view_service_invoicing_tree" + ).id, + "tree", + ), + ( + env.ref( + "energy_communities_service_invoicing.view_contract_contract_customer_form_platform_admin" + ).id, + "form", + ), + ], "res_model": "contract.contract", - # 'context': "{'type':'out_invoice'}", + "context": env["contract.contract"].get_service_invoicing_views_context(), + "domain": env["contract.contract"].get_service_invoicing_views_domain(), "type": "ir.actions.act_window", "target": "current", } diff --git a/energy_communities_service_invoicing/views/contract_views.xml b/energy_communities_service_invoicing/views/contract_views.xml index 924884b58..b19994cca 100644 --- a/energy_communities_service_invoicing/views/contract_views.xml +++ b/energy_communities_service_invoicing/views/contract_views.xml @@ -54,6 +54,61 @@ </field> </record> + <record id="view_contract_contract_customer_form_platform_admin" model="ir.ui.view"> + <field name="name">contract.contract.form (in energy_communities service_invoicing platform admin)</field> + <field name="model">contract.contract</field> + <field name="inherit_id" ref="product_contract.contract_contract_customer_form_view" /> + <field name="arch" type="xml"> + <xpath expr="//header" position="inside"> + <field name="status" widget="statusbar" /> + </xpath> + <xpath expr="//button[@name='action_preview']" position="after"> + <button + name="action_activate_contract" + type="object" + string="Activate" + attrs="{'invisible':[('status','not in',['paused'])]}" + /> + <button + name="action_modify_contract" + type="object" + string="Modify" + attrs="{'invisible':[('status','not in',['paused','in_progress'])]}" + /> + <button + name="action_close_contract" + type="object" + string="Close" + attrs="{'invisible':[('status','not in',['paused','in_progress'])]}" + /> + <button + name="action_reopen_contract" + type="object" + string="Reopen" + attrs="{'invisible':['|',('status','not in',['closed','closed_planned']),('successor_contract_id','!=',False)]}" + /> + </xpath> + <xpath expr="//field[@name='partner_id']" position="after"> + <field name="community_company_id" /> + </xpath> + <xpath expr="//field[@name='pricelist_id']" position="after"> + <field name="service_pack_id" /> + </xpath> + <xpath expr="//field[@name='user_id']" position="after"> + <field name="date_start" /> + <field name="last_date_invoiced" /> + <field name="recurring_next_date" /> + <field name="date_end" /> + <field name="discount" /> + <field name="predecessor_contract_id" /> + <field name="successor_contract_id" /> + <field name="closing_action" attrs="{'invisible':[('status','not in',['closed','closed_planned'])]}" /> + <field name="closing_action_description" attrs="{'invisible':[('status','not in',['closed','closed_planned'])]}" /> + <field name="sale_order_id" /> + </xpath> + </field> + </record> + <record id="view_contract_contract_customer_form_coord_admin" model="ir.ui.view"> <field name="name">contract.contract.form (in energy_communities service_invoicing coordinator)</field> <field name="model">contract.contract</field> @@ -110,58 +165,5 @@ </field> </record> - <record id="view_contract_contract_customer_form_platform_admin" model="ir.ui.view"> - <field name="name">contract.contract.form (in energy_communities service_invoicing platform admin)</field> - <field name="model">contract.contract</field> - <field name="inherit_id" ref="product_contract.contract_contract_customer_form_view" /> - <field name="arch" type="xml"> - <xpath expr="//header" position="inside"> - <field name="status" widget="statusbar" /> - </xpath> - <xpath expr="//button[@name='action_preview']" position="after"> - <button - name="action_activate_contract" - type="object" - string="Activate" - attrs="{'invisible':[('status','not in',['paused'])]}" - /> - <button - name="action_modify_contract" - type="object" - string="Modify" - attrs="{'invisible':[('status','not in',['paused','in_progress'])]}" - /> - <button - name="action_close_contract" - type="object" - string="Close" - attrs="{'invisible':[('status','not in',['paused','in_progress'])]}" - /> - <button - name="action_reopen_contract" - type="object" - string="Reopen" - attrs="{'invisible':['|',('status','not in',['closed','closed_planned']),('successor_contract_id','!=',False)]}" - /> - </xpath> - <xpath expr="//field[@name='partner_id']" position="after"> - <field name="community_company_id" /> - </xpath> - <xpath expr="//field[@name='pricelist_id']" position="after"> - <field name="service_pack_id" /> - </xpath> - <xpath expr="//field[@name='user_id']" position="after"> - <field name="date_start" /> - <field name="last_date_invoiced" /> - <field name="recurring_next_date" /> - <field name="date_end" /> - <field name="discount" /> - <field name="predecessor_contract_id" /> - <field name="successor_contract_id" /> - <field name="closing_action" attrs="{'invisible':[('status','not in',['closed','closed_planned'])]}" /> - <field name="closing_action_description" attrs="{'invisible':[('status','not in',['closed','closed_planned'])]}" /> - <field name="sale_order_id" /> - </xpath> - </field> - </record> + </odoo> diff --git a/energy_communities_service_invoicing/views/service_invoicing_views.xml b/energy_communities_service_invoicing/views/service_invoicing_views.xml index d8d507be2..683cdfda0 100644 --- a/energy_communities_service_invoicing/views/service_invoicing_views.xml +++ b/energy_communities_service_invoicing/views/service_invoicing_views.xml @@ -3,12 +3,10 @@ id="view_service_invoicing_window_platform_manager" model="ir.actions.act_window" > - <field name="name">Service Invoicing</field> + <field name="name">Service Contracts</field> <field name="res_model">contract.contract</field> <field name="view_mode">tree,form</field> - <field name="domain"> -[('community_company_id','!=',False)] - </field> + <field name="domain">[('community_company_id','!=',False)]</field> <field name="context">{"search_default_not_finished":1,"search_default_paused":1}</field> </record> @@ -16,12 +14,10 @@ id="view_service_invoicing_window_coord_admin" model="ir.actions.act_window" > - <field name="name">Service Invoicing</field> + <field name="name">Service Contracts</field> <field name="res_model">contract.contract</field> <field name="view_mode">tree,form</field> - <field name="domain"> -[('community_company_id','!=',False)] - </field> + <field name="domain">[('community_company_id','!=',False)]</field> <field name="context">{"search_default_not_finished":1,"search_default_paused":1}</field> </record> diff --git a/energy_communities_service_invoicing/wizards/service_invoicing_action_create.py b/energy_communities_service_invoicing/wizards/service_invoicing_action_create.py index 92e08d406..0f99cc40d 100644 --- a/energy_communities_service_invoicing/wizards/service_invoicing_action_create.py +++ b/energy_communities_service_invoicing/wizards/service_invoicing_action_create.py @@ -4,7 +4,6 @@ from odoo.tools.translate import _ from odoo.addons.energy_communities.utils import ( contract_utils, - get_successful_popup_message, sale_order_utils, ) @@ -13,6 +12,7 @@ from ..utils import ( get_existing_open_contract, raise_existing_same_open_contract_error, service_invoicing_form_view_for_platform_admins, + service_invoicing_tree_view, ) @@ -98,10 +98,7 @@ class ServiceInvoicingActionCreateWizard(models.TransientModel): community.parent_id, self.env.company.service_invoicing_payment_mode_id, ) - return get_successful_popup_message( - _("Service invoicing contracts successfully created"), - _("Visit Community Management section to manage them"), - ) + return service_invoicing_tree_view(self.env) else: service_invoicing_id = self._execute_create_one( self.community_company_id, self.company_id, self.payment_mode_id -- GitLab