Skip to content
Snippets Groups Projects
Commit 7da5c4c1 authored by daniquilez's avatar daniquilez
Browse files

[IMP] :sparkles: Avoid payment mode required on service contract creation

parent e638d009
No related branches found
No related tags found
2 merge requests!504Release 2025-03-11,!502Refactor module energy communities service invoicing
......@@ -83,17 +83,16 @@ class ContractUtils(Component):
sale_order_utils = self.component(
usage="sale.order.utils", model_name="sale.order"
)
service_invoicing_params = self._build_service_invoicing_params(
"modification",
executed_modification_action,
execution_date,
pricelist_id,
service_pack_id,
discount,
payment_mode_id,
)
new_service_invoicing_id = sale_order_utils.create_service_invoicing_initial(
**service_invoicing_params
**self._build_service_invoicing_params(
"modification",
executed_modification_action,
execution_date,
pricelist_id,
service_pack_id,
discount,
payment_mode_id,
)
)
# TODO:
# Do we really want new contract to be in_progress on a modification??
......
......@@ -23,7 +23,6 @@ class SaleOrderUtils(Component):
"pricelist_id": pricelist_id.id,
"service_invoicing_action": executed_action,
"service_invoicing_action_description": executed_action_description,
"payment_mode_id": payment_mode_id.id,
"order_line": [
(
0,
......@@ -36,6 +35,8 @@ class SaleOrderUtils(Component):
)
],
}
if payment_mode_id:
so_creation_dict["payment_mode_id"] = payment_mode_id.id
# Apply configuration sales team to service invoicing sales order
if company_id.service_invoicing_sale_team_id:
so_creation_dict["team_id"] = company_id.service_invoicing_sale_team_id.id
......@@ -83,11 +84,11 @@ class SaleOrderUtils(Component):
community_company_id,
service_pack_id,
pricelist_id,
payment_mode_id,
start_date,
discount,
executed_action,
executed_action_description="none",
payment_mode_id=False,
):
service_invoicing_id = self._create_service_invoicing(
company_id,
......
......@@ -10,10 +10,10 @@ class ResCompany(models.Model):
comodel_name="account.journal",
string="Service invoicing journal",
)
service_invoicing_payment_mode_id = fields.Many2one(
comodel_name="account.payment.mode",
string="Service invoicing payment mode",
)
# service_invoicing_payment_mode_id = fields.Many2one(
# comodel_name="account.payment.mode",
# string="Service invoicing payment mode",
# )
service_invoicing_sale_team_id = fields.Many2one(
comodel_name="crm.team",
string="Service invoicing sales team",
......
......@@ -7,7 +7,7 @@
<field name="state">code</field>
<field name="groups_id" eval="[(4,ref('energy_communities.group_platform_manager'))]" />
<field name="code">
action = model.get_service_invoicing_action_create_wizard_form_view()
action = model.get_multiple_service_invoicing_action_create_wizard_form_view()
</field>
</record>
<record id="view_service_invocing_company_form" model="ir.ui.view">
......@@ -20,7 +20,6 @@
<group>
<field name="id" invisible="1"/>
<field name="service_invoicing_journal_id" domain="[('company_id', '=', id)]" />
<field name="service_invoicing_payment_mode_id" domain="[('company_id', '=', id)]" />
<field name="service_invoicing_sale_team_id" domain="[('company_id', '=', id)]" />
</group>
</page>
......
......@@ -10,7 +10,13 @@
<sheet>
<group>
<field name="executed_action" invisible="1" />
<field name="service_invoicing_id" required="1" domain="[('community_company_id','!=',False)]"/>
<field
name="service_invoicing_id"
required="1"
readonly="1"
domain="[('community_company_id','!=',False)]"
options="{'no_open': True}"
/>
<field name="execution_date" required="1"/>
<field
name="service_pack_id"
......
......@@ -21,6 +21,9 @@ class ServiceInvoicingActionCreateWizard(models.TransientModel):
_description = "Create service invoicing for an energy community"
_inherit = ["user.currentcompany.mixin"]
creation_type = fields.Selection(
[("single", "Single"), ("multiple", "Multiple")], default="single"
)
execution_date = fields.Date(string="Execution date")
company_id = fields.Many2one("res.company", string="Coordinator")
community_company_id = fields.Many2one(
......@@ -76,27 +79,23 @@ class ServiceInvoicingActionCreateWizard(models.TransientModel):
@api.depends("company_id", "community_company_mids")
def _compute_allowed_payment_mode_ids(self):
for record in self:
if record.community_company_mids:
query = [("company_id", "=", self.user_current_company.id)]
else:
query = [("company_id", "=", record.company_id.id)]
record.allowed_payment_mode_ids = self.env["account.payment.mode"].search(
query
[("company_id", "=", self.user_current_company.id)]
)
@api.onchange("company_id")
def _compute_service_invoicing_action_create_wizard_allowed_values(self):
for record in self:
record._compute_pack_product_categ_id()
record._compute_allowed_community_company_ids()
record._compute_allowed_payment_mode_ids()
def execute_create(self):
if self.community_company_mids:
if self.creation_type == "multiple":
for community in self.community_company_mids:
self._execute_create_one(
community,
community.parent_id,
self.env.company.service_invoicing_payment_mode_id,
)
return service_invoicing_tree_view(self.env)
else:
......@@ -107,7 +106,9 @@ class ServiceInvoicingActionCreateWizard(models.TransientModel):
self.env, service_invoicing_id
)
def _execute_create_one(self, community_company_id, company_id, payment_mode_id):
def _execute_create_one(
self, community_company_id, company_id, payment_mode_id=False
):
self._validate_service_invoicing_action_create([community_company_id.id])
existing_closed_contract = get_existing_last_closed_contract(
self.env, company_id.partner_id, community_company_id
......@@ -130,15 +131,15 @@ class ServiceInvoicingActionCreateWizard(models.TransientModel):
community_company_id,
self.service_pack_id,
self.pricelist_id,
payment_mode_id,
self.execution_date,
self.discount,
"activate",
"active_platform_service_invocing",
payment_mode_id,
)
return service_invoicing_id
def get_service_invoicing_action_create_wizard_form_view(self):
def get_multiple_service_invoicing_action_create_wizard_form_view(self):
if "active_ids" in self.env.context.keys():
self._validate_service_invoicing_action_create(
self.env.context["active_ids"]
......@@ -148,6 +149,7 @@ class ServiceInvoicingActionCreateWizard(models.TransientModel):
)
wizard = self.env["service.invoicing.action.create.wizard"].create(
{
"creation_type": "multiple",
"community_company_mids": self.env.context["active_ids"],
}
)
......@@ -168,6 +170,10 @@ class ServiceInvoicingActionCreateWizard(models.TransientModel):
return False
def _validate_service_invoicing_action_create(self, company_id_list):
if self.env.company.hierarchy_level != "instance":
raise ValidationError(
_("This action is only allowed when you're on instance level.")
)
impacted_records = self.env["res.company"].browse(company_id_list)
# Check all selected companies are communities
hierarchy_levels = list(set(impacted_records.mapped("hierarchy_level")))
......@@ -191,10 +197,3 @@ class ServiceInvoicingActionCreateWizard(models.TransientModel):
record.name
)
)
# Check current company has configuration payment mode for multicompany creation
if not self.env.company.service_invoicing_payment_mode_id:
raise ValidationError(
_(
"Platform {} must have a service invoicing payment mode defined"
).format(self.env.company.name)
)
......@@ -6,9 +6,10 @@
<field name="name">service.invoicing.action.create.wizard.form</field>
<field name="model">service.invoicing.action.create.wizard</field>
<field name="arch" type="xml">
<form string="Service invoicing">
<form string="Service Contract">
<sheet>
<group>
<field name="creation_type" invisible="1" />
<field name="allowed_community_company_ids" invisible="1" />
<field name="allowed_payment_mode_ids" invisible="1" />
<field name="pack_product_categ_id" invisible="1" />
......@@ -16,21 +17,30 @@
<field
name="company_id"
domain="[('hierarchy_level','=','coordinator')]"
attrs="{'invisible':[('community_company_mids','!=',[])],'required':[('community_company_mids','=',[])]}"
attrs="{'invisible':[('creation_type','=','multiple')],'required':[('creation_type','=','single')]}"
/>
<field
name="community_company_id"
attrs="{'invisible':[('community_company_mids','!=',[])],'required':[('community_company_mids','=',[])]}"
attrs="{'invisible':[('creation_type','=','multiple')],'required':[('creation_type','=','single')]}"
/>
<field name="community_company_mids" />
<field
name="community_company_mids"
attrs="{'invisible':[('creation_type','=','single')],'required':[('creation_type','=','multiple')]}"
widget="many2many"
>
<tree>
<field name="name"/>
<field name="parent_id"/>
</tree>
</field>
<field name="service_pack_id"
required="1"
domain="[('categ_id','=',pack_product_categ_id)]"
required="1"
/>
<field name="pricelist_id" required="1" domain="[('company_id','=',False)]"/>
<field
name="payment_mode_id"
attrs="{'invisible':[('community_company_mids','!=',[])],'required':[('community_company_mids','=',[])]}"
attrs="{'invisible':[('creation_type','=','multiple')]}"
/>
<field name="discount" required="1" />
</group>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment