Skip to content

Commit 69ec319

Browse files
committed
[IMP] sale_timesheet_project_manual - pre-commit stuff
1 parent 1739a10 commit 69ec319

File tree

6 files changed

+115
-93
lines changed

6 files changed

+115
-93
lines changed

sale_timesheet_project_manual/__manifest__.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

44
{
5-
'name': 'Sale Timesheet Project Manual',
6-
'summary': """
5+
"name": "Sale Timesheet Project Manual",
6+
"summary": """
77
Allows to create the project/tasks before the sale confirmation""",
8-
'version': '11.0.1.0.1',
9-
'license': 'AGPL-3',
10-
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
11-
'website': 'https://github.com/OCA/sale-workflow',
12-
'depends': [
13-
'sale_timesheet',
8+
"version": "16.0.1.0.0",
9+
"license": "AGPL-3",
10+
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
11+
"website": "https://github.com/OCA/sale-workflow",
12+
"depends": [
13+
"sale_timesheet",
1414
],
15-
'data': [
16-
'views/sale_order.xml',
17-
],
18-
'demo': [
15+
"data": [
16+
"views/sale_order.xml",
1917
],
18+
"demo": [],
2019
}
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
11
# Copyright 2018 ACSONE SA/NV
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from odoo import api, fields, models, _
4+
from odoo import _, api, fields, models
55
from odoo.exceptions import ValidationError
66

77

88
class SaleOrder(models.Model):
99

10-
_inherit = 'sale.order'
10+
_inherit = "sale.order"
1111

1212
action_project_manual_allowed = fields.Boolean(
13-
compute='_compute_action_project_manual_allowed'
13+
compute="_compute_action_project_manual_allowed"
1414
)
1515

1616
@api.multi
1717
@api.depends(
18-
'state',
19-
'order_line.is_service',
20-
'order_line.product_id.service_tracking',
18+
"state",
19+
"order_line.is_service",
20+
"order_line.product_id.service_tracking",
2121
)
2222
def _compute_action_project_manual_allowed(self):
2323
for rec in self:
24-
rec.action_project_manual_allowed = (
25-
rec.state in ('draft', 'sent') and
26-
any([
27-
line.is_service and
28-
line.product_id.service_tracking in (
29-
'task_global_project',
30-
'project_only',
31-
'task_new_project'
32-
)
24+
rec.action_project_manual_allowed = rec.state in ("draft", "sent") and any(
25+
[
26+
line.is_service
27+
and line.product_id.service_tracking
28+
in ("task_global_project", "project_only", "task_new_project")
3329
for line in rec.order_line
34-
])
30+
]
3531
)
3632

3733
@api.multi
@@ -43,8 +39,11 @@ def action_project_manual(self):
4339
def action_project_manual_allowed_check(self):
4440
for rec in self:
4541
if not rec.action_project_manual_allowed:
46-
raise ValidationError(_(
47-
"You can anticipate the project creation only for "
48-
"draft quotations which contain service with timesheet "
49-
"generation. (SO: %s)"
50-
) % rec.display_name)
42+
raise ValidationError(
43+
_(
44+
"You can anticipate the project creation only for "
45+
"draft quotations which contain service with timesheet "
46+
"generation. (SO: %s)"
47+
)
48+
% rec.display_name
49+
)

sale_timesheet_project_manual/tests/test_sale_timesheet_project_manual.py

Lines changed: 68 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,80 @@
11
# Copyright 2018 ACSONE SA/NV
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from odoo.tests.common import SavepointCase
54
from odoo.exceptions import ValidationError
5+
from odoo.tests.common import SavepointCase
66

77

88
class TestSaleTimesheetProjectManual(SavepointCase):
9-
109
@classmethod
1110
def setUpClass(cls):
1211
super(TestSaleTimesheetProjectManual, cls).setUpClass()
13-
cls.Product = cls.env['product.product']
14-
cls.SaleOrder = cls.env['sale.order']
15-
16-
cls.partner_agrolait = cls.env.ref('base.res_partner_2')
17-
cls.uom_unit_wt = cls.env.ref('product.uom_categ_wtime')
18-
19-
cls.product_service_task = cls.Product.create({
20-
'name': "Service (with task)",
21-
'type': "service",
22-
'service_policy': 'delivered_timesheet',
23-
'service_tracking': 'task_new_project',
24-
'uom_id': cls.uom_unit_wt.id,
25-
'uom_po_id': cls.uom_unit_wt.id,
26-
})
27-
28-
cls.product_service_project = cls.Product.create({
29-
'name': "Service (only project)",
30-
'type': "service",
31-
'service_policy': 'delivered_timesheet',
32-
'service_tracking': 'project_only',
33-
'uom_id': cls.uom_unit_wt.id,
34-
'uom_po_id': cls.uom_unit_wt.id,
35-
})
12+
cls.Product = cls.env["product.product"]
13+
cls.SaleOrder = cls.env["sale.order"]
14+
15+
cls.partner_agrolait = cls.env.ref("base.res_partner_2")
16+
cls.uom_unit_wt = cls.env.ref("product.uom_categ_wtime")
17+
18+
cls.product_service_task = cls.Product.create(
19+
{
20+
"name": "Service (with task)",
21+
"type": "service",
22+
"service_policy": "delivered_timesheet",
23+
"service_tracking": "task_new_project",
24+
"uom_id": cls.uom_unit_wt.id,
25+
"uom_po_id": cls.uom_unit_wt.id,
26+
}
27+
)
28+
29+
cls.product_service_project = cls.Product.create(
30+
{
31+
"name": "Service (only project)",
32+
"type": "service",
33+
"service_policy": "delivered_timesheet",
34+
"service_tracking": "project_only",
35+
"uom_id": cls.uom_unit_wt.id,
36+
"uom_po_id": cls.uom_unit_wt.id,
37+
}
38+
)
3639

3740
def test_01_project_manual(self):
38-
order = self.SaleOrder.create({
39-
'partner_id': self.partner_agrolait.id,
40-
'order_line': [
41-
(0, 0, {
42-
'product_id': self.product_service_task.id,
43-
'name': "Task 1",
44-
'product_uom_qty': 10,
45-
'product_uom': self.uom_unit_wt.id,
46-
}),
47-
(0, 0, {
48-
'product_id': self.product_service_task.id,
49-
'name': "Task 2",
50-
'product_uom_qty': 15,
51-
'product_uom': self.uom_unit_wt.id,
52-
}),
53-
(0, 0, {
54-
'product_id': self.product_service_project.id,
55-
'name': "Task (Misc)",
56-
'product_uom_qty': 15,
57-
'product_uom': self.uom_unit_wt.id,
58-
})
59-
]
60-
})
41+
order = self.SaleOrder.create(
42+
{
43+
"partner_id": self.partner_agrolait.id,
44+
"order_line": [
45+
(
46+
0,
47+
0,
48+
{
49+
"product_id": self.product_service_task.id,
50+
"name": "Task 1",
51+
"product_uom_qty": 10,
52+
"product_uom": self.uom_unit_wt.id,
53+
},
54+
),
55+
(
56+
0,
57+
0,
58+
{
59+
"product_id": self.product_service_task.id,
60+
"name": "Task 2",
61+
"product_uom_qty": 15,
62+
"product_uom": self.uom_unit_wt.id,
63+
},
64+
),
65+
(
66+
0,
67+
0,
68+
{
69+
"product_id": self.product_service_project.id,
70+
"name": "Task (Misc)",
71+
"product_uom_qty": 15,
72+
"product_uom": self.uom_unit_wt.id,
73+
},
74+
),
75+
],
76+
}
77+
)
6178

6279
self.assertTrue(order.action_project_manual_allowed)
6380
order.action_cancel()
@@ -74,22 +91,20 @@ def test_01_project_manual(self):
7491
self.assertTrue(order.name in analytic_account.name)
7592

7693
projects = analytic_account.project_ids
77-
line_tasks = order.order_line.mapped('task_id')
94+
line_tasks = order.order_line.mapped("task_id")
7895

7996
self.assertEqual(len(projects), 1)
8097
self.assertEqual(len(line_tasks), 2)
8198

82-
self.assertEqual(
83-
line_tasks.mapped('project_id'),
84-
projects)
99+
self.assertEqual(line_tasks.mapped("project_id"), projects)
85100

86101
order.action_confirm()
87102
self.assertFalse(order.action_project_manual_allowed)
88103
order.invalidate_cache()
89104

90105
analytic_account_1 = order.analytic_account_id
91106
projects_1 = analytic_account.project_ids
92-
line_tasks_1 = order.order_line.mapped('task_id')
107+
line_tasks_1 = order.order_line.mapped("task_id")
93108

94109
self.assertEqual(analytic_account_1, analytic_account)
95110
self.assertEqual(projects_1, projects)

sale_timesheet_project_manual/views/sale_order.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<!-- Copyright 2018 ACSONE SA/NV
33
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
4-
54
<odoo>
65

76
<record model="ir.ui.view" id="sale_order_form_view">
87
<field name="name">sale.order.form (in sale_order_project_manual)</field>
98
<field name="model">sale.order</field>
10-
<field name="inherit_id" ref="sale.view_order_form"/>
9+
<field name="inherit_id" ref="sale.view_order_form" />
1110
<field name="arch" type="xml">
1211

1312
<button name="action_confirm" position="before">
14-
<field name="action_project_manual_allowed" invisible="1"/>
15-
<button name="action_project_manual" type="object"
16-
string="Generate Project/Task"
17-
attrs="{'invisible': [('action_project_manual_allowed', '=', False)]}"/>
13+
<field name="action_project_manual_allowed" invisible="1" />
14+
<button
15+
name="action_project_manual"
16+
type="object"
17+
string="Generate Project/Task"
18+
attrs="{'invisible': [('action_project_manual_allowed', '=', False)]}"
19+
/>
1820
</button>
1921

2022
</field>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../sale_timesheet_project_manual
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

0 commit comments

Comments
 (0)