Skip to content

Commit 2f8094f

Browse files
committed
[FIX] hr_timesheet_name_customer: better impl with compute
Before this commit, the creation would fail when no 'name' value was provided.
1 parent ecd57ac commit 2f8094f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

hr_timesheet_name_customer/models/hr_timesheet_name_customer.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
class NameCustomer(models.Model):
77
_inherit = "account.analytic.line"
88

9-
name_customer = fields.Char(string="Customer Description")
10-
"""override create method, initialize name_customer"""
9+
name_customer = fields.Char(
10+
string="Customer Description",
11+
compute="_compute_name_customer",
12+
store=True,
13+
readonly=False,
14+
)
1115

12-
@api.model_create_multi
13-
def create(self, vals_list):
14-
for vals in vals_list:
15-
if not vals.get("name_customer"):
16-
vals["name_customer"] = vals["name"]
17-
return super(NameCustomer, self).create(vals_list)
16+
@api.depends("name")
17+
def _compute_name_customer(self):
18+
for rec in self:
19+
if not rec.name_customer and rec.name:
20+
rec.name_customer = rec.name

0 commit comments

Comments
 (0)