[REF] {hr,sale}_timesheet: refactor timesheet form view

Before this commit timesheet community and enterprise form view
where different from each other because of that if we want to
change something in timesheet form we have to do change in both
view and sometimes it is hard to keep track of both view.

This commit use single form view in both community and enterprise
so it'll easier to change something in timesheet form view and
it'll remove some technical debt.

task-3255754

closes odoo/odoo#117748

Related: odoo/enterprise#39343
Related: odoo/upgrade#4520
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
This commit is contained in:
Kartik Chavda
2023-04-28 16:04:22 +02:00
parent 272a1b9a69
commit 270c4732f4
3 changed files with 50 additions and 7 deletions
@@ -9,8 +9,9 @@
<field name="readonly_timesheet" invisible="1"/>
<field name="date" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="employee_id" invisible="1" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="project_id" required="1" options="{'no_create_edit': True, 'no_open': 1}" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="task_id" optional="show" options="{'no_create_edit': True, 'no_open': True}" widget="task_with_hours" context="{'default_project_id': project_id}" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="project_id" required="1" options="{'no_create_edit': True}" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="task_id" optional="show" options="{'no_create_edit': True}" widget="task_with_hours" context="{'default_project_id': project_id}"
attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="name" optional="show" required="0" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="unit_amount" optional="show" widget="timesheet_uom" sum="Total" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"
decoration-danger="unit_amount &gt; 24 or unit_amount &lt; 0" decoration-muted="unit_amount == 0"/>
@@ -123,10 +124,10 @@
<group>
<group>
<field name="readonly_timesheet" invisible="1"/>
<field name="project_id" required="1" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="task_id" widget="task_with_hours" context="{'default_project_id': project_id}"
<field name="project_id" required="1" options="{'no_create_edit': True}"
attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="name" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="task_id" widget="task_with_hours" options="{'no_create_edit': True}"
context="{'default_project_id': project_id}" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="company_id" groups="base.group_multi_company" invisible="1"/>
</group>
<group>
@@ -138,6 +139,7 @@
<field name="company_id" invisible="1"/>
</group>
</group>
<field name="name" placeholder="Describe your activity" widget="text" required="0" nolabel="1" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
</sheet>
</form>
</field>
@@ -151,8 +153,9 @@
<field name="priority">10</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='date']" position="before">
<field name="employee_id" required="1" context="{'active_test': True}" attrs="{'readonly': [('readonly_timesheet', '=', True)]}"/>
<field name="user_id" invisible="1"/>
<field name="employee_id" required="1" groups="hr_timesheet.group_hr_timesheet_approver" widget="many2one_avatar_employee"
attrs="{'readonly': [('readonly_timesheet', '=', True)]}" context="{'active_test': True}"/>
<field name="user_id" invisible="1" groups="hr_timesheet.group_hr_timesheet_approver"/>
</xpath>
</field>
</record>
+22
View File
@@ -168,3 +168,25 @@ class AccountAnalyticLine(models.Model):
if mapping_entry:
return mapping_entry.cost
return super()._hourly_cost()
def action_sale_order_from_timesheet(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': _('Sale Order'),
'res_model': 'sale.order',
'views': [[False, 'form']],
'context': {'create': False, 'show_sale': True},
'res_id': self.order_id.id,
}
def action_invoice_from_timesheet(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': _('Invoice'),
'res_model': 'account.move',
'views': [[False, 'form']],
'context': {'create': False},
'res_id': self.timesheet_invoice_id.id,
}
@@ -61,6 +61,24 @@
<field name="allow_billable" invisible="1" groups="sales_team.group_sale_salesman"/>
<field name="so_line" widget="so_line_field" options='{"no_create": True}' context="{'create': False, 'edit': False, 'delete': False, 'with_price_unit': True}" attrs="{'invisible': [('allow_billable', '=', False)], 'readonly': [('readonly_timesheet', '=', True)]}" placeholder="Non-billable" groups="sales_team.group_sale_salesman"/>
</xpath>
<xpath expr="//group" position="before">
<t groups="sales_team.group_sale_salesman">
<field name="order_id" invisible="1"/>
<field name="timesheet_invoice_id" invisible="1"/>
<div class="oe_button_box" name="button_box">
<button name="action_sale_order_from_timesheet" type="object" class="oe_stat_button" icon="fa-dollar" attrs="{'invisible': [('order_id', '=', False)]}">
<div class="o_stat_info">
<span class="o_stat_text">Sales Order</span>
</div>
</button>
<button name="action_invoice_from_timesheet" type="object" class="oe_stat_button" icon="fa-pencil-square-o" attrs="{'invisible': [('timesheet_invoice_id', '=', False)]}">
<div class="o_stat_info">
<span class="o_stat_text">Invoice</span>
</div>
</button>
</div>
</t>
</xpath>
</field>
</record>