summaryrefslogtreecommitdiff
path: root/addons/sale_timesheet_edit
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/sale_timesheet_edit
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/sale_timesheet_edit')
-rw-r--r--addons/sale_timesheet_edit/__init__.py4
-rw-r--r--addons/sale_timesheet_edit/__manifest__.py26
-rw-r--r--addons/sale_timesheet_edit/models/__init__.py5
-rw-r--r--addons/sale_timesheet_edit/models/account_analytic_line.py20
-rw-r--r--addons/sale_timesheet_edit/models/project.py15
-rw-r--r--addons/sale_timesheet_edit/static/src/js/so_line_one2many.js29
-rw-r--r--addons/sale_timesheet_edit/views/assets.xml10
-rw-r--r--addons/sale_timesheet_edit/views/project_task.xml41
8 files changed, 150 insertions, 0 deletions
diff --git a/addons/sale_timesheet_edit/__init__.py b/addons/sale_timesheet_edit/__init__.py
new file mode 100644
index 00000000..dc5e6b69
--- /dev/null
+++ b/addons/sale_timesheet_edit/__init__.py
@@ -0,0 +1,4 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import models
diff --git a/addons/sale_timesheet_edit/__manifest__.py b/addons/sale_timesheet_edit/__manifest__.py
new file mode 100644
index 00000000..fe730ff9
--- /dev/null
+++ b/addons/sale_timesheet_edit/__manifest__.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+# TODO: [XBO] merge with sale_timesheet module in master
+{
+ 'name': 'Sales Timesheet Edit',
+ 'category': 'Hidden',
+ 'summary': 'Edit the sale order line linked in the timesheets',
+ 'description': """
+Allow to edit sale order line in the timesheets
+===============================================
+
+This module adds the edition of the sale order line
+set in the timesheets. This allows adds more flexibility
+to the user to easily change the sale order line on a
+timesheet in task form view when it is needed.
+""",
+ 'depends': ['sale_timesheet'],
+ 'data': [
+ 'views/assets.xml',
+ 'views/project_task.xml',
+ ],
+ 'demo': [],
+ 'auto_install': True,
+ 'license': 'LGPL-3',
+}
diff --git a/addons/sale_timesheet_edit/models/__init__.py b/addons/sale_timesheet_edit/models/__init__.py
new file mode 100644
index 00000000..bf8826f4
--- /dev/null
+++ b/addons/sale_timesheet_edit/models/__init__.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import account_analytic_line
+from . import project
diff --git a/addons/sale_timesheet_edit/models/account_analytic_line.py b/addons/sale_timesheet_edit/models/account_analytic_line.py
new file mode 100644
index 00000000..5ff797dd
--- /dev/null
+++ b/addons/sale_timesheet_edit/models/account_analytic_line.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models
+
+
+# TODO: [XBO] merge with account.analytic.line in the sale_timesheet module in master.
+class AccountAnalyticLine(models.Model):
+ _inherit = 'account.analytic.line'
+
+ is_so_line_edited = fields.Boolean()
+
+ @api.depends('task_id.sale_line_id', 'project_id.sale_line_id', 'project_id.allow_billable', 'employee_id')
+ def _compute_so_line(self):
+ super(AccountAnalyticLine, self.filtered(lambda t: not t.is_so_line_edited))._compute_so_line()
+
+ def _check_sale_line_in_project_map(self):
+ # TODO: [XBO] remove me in master, now we authorize to manually edit the so_line, then this so_line can be different of the one in task/project/map_entry
+ # !!! Override of the method in sale_timesheet !!!
+ return
diff --git a/addons/sale_timesheet_edit/models/project.py b/addons/sale_timesheet_edit/models/project.py
new file mode 100644
index 00000000..b10bafdd
--- /dev/null
+++ b/addons/sale_timesheet_edit/models/project.py
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import models
+
+
+class Project(models.Model):
+ _inherit = 'project.project'
+
+ def _get_not_billed_timesheets(self):
+ """ Get the timesheets not invoiced and the SOL has not manually been edited
+ FIXME: [XBO] this change must be done in the _update_timesheets_sale_line_id
+ rather than this method in master to keep the initial behaviour of this method.
+ """
+ return super(Project, self)._get_not_billed_timesheets() - self.mapped('timesheet_ids').filtered('is_so_line_edited')
diff --git a/addons/sale_timesheet_edit/static/src/js/so_line_one2many.js b/addons/sale_timesheet_edit/static/src/js/so_line_one2many.js
new file mode 100644
index 00000000..fd8f7489
--- /dev/null
+++ b/addons/sale_timesheet_edit/static/src/js/so_line_one2many.js
@@ -0,0 +1,29 @@
+odoo.define('sale_timesheet_edit.so_line_many2one', function (require) {
+"use strict";
+
+const fieldRegistry = require('web.field_registry');
+const FieldOne2Many = require('web.relational_fields').FieldOne2Many;
+
+const SoLineOne2Many = FieldOne2Many.extend({
+ _onFieldChanged: function (ev) {
+ if (
+ ev.data.changes &&
+ ev.data.changes.hasOwnProperty('timesheet_ids') &&
+ ev.data.changes.timesheet_ids.operation === 'UPDATE' &&
+ ev.data.changes.timesheet_ids.data &&
+ ev.data.changes.timesheet_ids.data.hasOwnProperty('so_line')) {
+ const line = this.value.data.find(line => {
+ return line.id === ev.data.changes.timesheet_ids.id;
+ });
+ if (!line.is_so_line_edited) {
+ ev.data.changes.timesheet_ids.data.is_so_line_edited = true;
+ }
+ }
+ this._super.apply(this, arguments);
+ }
+});
+
+
+fieldRegistry.add('so_line_one2many', SoLineOne2Many);
+
+});
diff --git a/addons/sale_timesheet_edit/views/assets.xml b/addons/sale_timesheet_edit/views/assets.xml
new file mode 100644
index 00000000..b8909b44
--- /dev/null
+++ b/addons/sale_timesheet_edit/views/assets.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+
+ <template id="assets_backend" inherit_id="web.assets_backend">
+ <xpath expr="script[last()]" position="after">
+ <script type="text/javascript" src="/sale_timesheet_edit/static/src/js/so_line_one2many.js"></script>
+ </xpath>
+ </template>
+
+</odoo>
diff --git a/addons/sale_timesheet_edit/views/project_task.xml b/addons/sale_timesheet_edit/views/project_task.xml
new file mode 100644
index 00000000..f9f7e38e
--- /dev/null
+++ b/addons/sale_timesheet_edit/views/project_task.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+
+ <!-- This view can be removed to change only if it is needed in the inherit view in sale_timesheet -->
+ <record id="project_task_view_form_inherit_sale_timesheet_edit" model="ir.ui.view">
+ <field name="name">project.task.form.view.form.inherit.sale.timesheet.edit</field>
+ <field name="model">project.task</field>
+ <field name="inherit_id" ref="sale_timesheet.project_task_view_form_inherit_sale_timesheet"/>
+ <field name="arch" type="xml">
+ <xpath expr="//field[@name='timesheet_ids']" position="attributes">
+ <attribute name="widget">so_line_one2many</attribute>
+ </xpath>
+ <xpath expr="//field[@name='timesheet_ids']/tree/field[@name='so_line']" position="attributes">
+ <attribute name="readonly">0</attribute>
+ <attribute name="domain">[('is_service', '=', True), ('order_partner_id', 'child_of', parent.commercial_partner_id), ('is_expense', '=', False), ('state', 'in', ['sale', 'done']), ('order_id', '=?', parent.project_sale_order_id)]</attribute>
+ <attribute name="options">{'no_create': True, 'no_open': True}</attribute>
+ </xpath>
+ </field>
+ </record>
+
+ <!--
+ TODO: [XBO] In master, add this view in the sale_timesheet when we will merge of the both modules
+ Don't forget to change the inherit_id to have the correct view in sale_timesheet,
+ since the view above can be merged with project_task_view_form_inherit_sale_timesheet view.
+ -->
+ <record id="project_task_view_form_inherit_sale_timesheet_editable" model="ir.ui.view">
+ <field name="name">project.task.form.view.form.inherit.sale.timesheet.editable</field>
+ <field name="model">project.task</field>
+ <field name="inherit_id" ref="project_task_view_form_inherit_sale_timesheet_edit"/>
+ <field name="arch" type="xml">
+ <xpath expr="//field[@name='timesheet_ids']/tree/field[@name='so_line']" position="attributes">
+ <attribute name="options">{'no_create': True}</attribute>
+ </xpath>
+ <xpath expr="//field[@name='timesheet_ids']/tree" position="inside">
+ <field name="is_so_line_edited" invisible="1" />
+ </xpath>
+ </field>
+ <field name="groups_id" eval="[(4, ref('sales_team.group_sale_salesman'))]"/>
+ </record>
+
+</odoo>