19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:12 +01:00
parent 79f83631d5
commit 73afc09215
6267 changed files with 1534193 additions and 1130106 deletions

View file

@ -0,0 +1 @@
from . import project_template_create_wizard

View file

@ -0,0 +1,67 @@
from odoo import api, Command, fields, models
class ProjectTemplateCreateWizard(models.TransientModel):
_inherit = 'project.template.create.wizard'
partner_id = fields.Many2one("res.partner")
allow_billable = fields.Boolean(related="template_id.allow_billable")
role_to_users_ids = fields.One2many(compute="_compute_role_to_users_ids", readonly=False, store=True)
@api.depends("template_id")
def _compute_role_to_users_ids(self):
for wizard in self:
wizard.role_to_users_ids = (
[Command.clear()] +
[
Command.create({
'role_id': role.id,
'user_ids': [Command.clear()],
})
for role in wizard.template_id.task_ids.role_ids
]
if wizard.template_id else [Command.clear()]
)
def _get_template_whitelist_fields(self):
res = super()._get_template_whitelist_fields()
if self.allow_billable:
res.append("partner_id")
return res
@api.model
def action_open_template_view(self):
action = super().action_open_template_view()
if self.env.context.get("from_sale_order_action"):
context = dict(action.get("context", {}))
context.update({
"default_partner_id": self.env.context.get("default_partner_id"),
"default_reinvoiced_sale_order_id": self.env.context.get("default_reinvoiced_sale_order_id"),
"default_sale_line_id": self.env.context.get("default_sale_line_id"),
})
action["context"] = context
return action
def action_create_project_from_so(self):
"""Create a project either from template or directly if no template is set."""
self.ensure_one()
if self.template_id:
project = self._create_project_from_template()
else:
sale_order = self.env['sale.order'].browse(self.env.context.get("default_sale_order_id"))
so_line = sale_order.order_line[:1]
product = so_line.product_id
values = {
'partner_id': sale_order.partner_id.id,
'company_id': sale_order.company_id.id,
}
if len(sale_order.order_line) == 1:
values['name'] = (
f"{sale_order.name} - [{product.default_code}] {product.name}"
if product.default_code
else f"{sale_order.name} - {product.name}"
)
else:
values['name'] = sale_order.name
project = self.env['project.project'].create(values)
return project.action_view_tasks()

View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="project_project_view_form_simplified_template" model="ir.ui.view">
<field name="name">project.project.create.wizard.form</field>
<field name="model">project.template.create.wizard</field>
<field name="inherit_id" ref="project.project_project_view_form_simplified_template"/>
<field name="arch" type="xml">
<field name="date_start" position="before">
<field
name="partner_id"
string="Customer"
invisible="not allow_billable"
placeholder="Select who to bill..."
widget="res_partner_many2one"
options="{'no_create_edit': True, 'no_open': True}"
/>
</field>
</field>
</record>
<record id="sale_project_view_form_simplified_template" model="ir.ui.view">
<field name="name">sale.project.create.wizard.form</field>
<field name="model">project.template.create.wizard</field>
<field name="inherit_id" ref="project.project_project_view_form_simplified_template"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="partner_id" position="replace"/>
<xpath expr="//div[hasclass('oe_title')]" position="replace"/>
<xpath expr="//label[@for='alias_name']" position="replace"/>
<xpath expr="//group/group/div[field[@name='alias_name']]" position="replace"/>
<field name="date_start" position="before">
<field
name="template_id"
string="Project Template"
placeholder="New project"
domain="[('is_template', '=', True)]"
context="{'default_is_template': True}"
/>
</field>
<xpath expr="//field[@name='date_start']" position="attributes">
<attribute name="invisible">not template_id</attribute>
</xpath>
<xpath expr="//form/footer/button[@name='create_project_from_template']" position="attributes">
<attribute name="name">action_create_project_from_so</attribute>
</xpath>
</field>
</record>
</odoo>