bemade_fsm: Improved task naming. Fixes Dur-Pro/bemade-addons#89.

This commit is contained in:
Marc Durepos 2023-08-28 19:15:03 -04:00
parent 83d84a7bfa
commit 853862cde1
3 changed files with 31 additions and 8 deletions

View file

@ -1,6 +1,7 @@
from odoo import fields, models, api, _, Command
from odoo.exceptions import ValidationError
from odoo.tools import float_round
import re
class SaleOrder(models.Model):

View file

@ -65,8 +65,9 @@ class Task(models.Model):
prev_seqs = self.sale_order_id.tasks_ids and \
self.sale_order_id.tasks_ids.mapped('work_order_number')
if prev_seqs:
seq += max(map(lambda n: int(re.search("\d+$", n).start() or 0),
prev_seqs))
pattern = re.compile(r"\d+$")
matches = map(lambda n: pattern.search(n), prev_seqs)
seq += max(map(lambda n: int(n.group(1)) if n else 0), matches)
rec.work_order_number = rec.sale_order_id.name.replace('SO', 'WO', 1) \
+ f"-{seq}"
return res
@ -190,13 +191,15 @@ class Task(models.Model):
assert rec.is_fsm, "This method should only be called on FSM tasks."
template = rec.sale_line_id and rec.sale_line_id.product_id.task_template_id
name_parts = rec.sale_line_id and rec.sale_line_id.name.split('\n')
title = name_parts and name_parts[0] or rec.sale_line_id.product_id.name
if not rec.parent_id:
rec.name = f"{rec.sale_order_id.partner_shipping_id.name} - " \
f"{rec.sale_line_id.name}"
f"{title}"
if template:
rec.name += f" ({template.name})"
else:
rec.name = f"{template.name or rec.sale_line_id.name or rec.name}"
rec.name = template.name or title or rec.name
@property
def root_ancestor(self):

View file

@ -25,10 +25,10 @@ class TestSalesOrder(BemadeFSMBaseTest):
partner = self._generate_partner()
so = self._generate_sale_order(partner=partner)
parent_template = self._generate_task_template(structure=[2, 1],
names=['Parent Template',
'Child Template',
'Grandchild Template'])
child_template_1= parent_template.subtasks[0]
names=['Parent Template',
'Child Template',
'Grandchild Template'])
child_template_1 = parent_template.subtasks[0]
child_template_2 = parent_template.subtasks[1]
grandchild_template = parent_template.subtasks[0].subtasks[0]
product = self._generate_product(task_template=parent_template)
@ -252,6 +252,25 @@ class TestSalesOrder(BemadeFSMBaseTest):
self.assertFalse(subtask1.user_ids)
self.assertFalse(subtask2.user_ids)
def test_long_line_name_overflows_to_task_description(self):
so = self._generate_sale_order()
product = self._generate_product()
product.description_sale = "This is a long product description.\n" \
"It even spans multiple lines.\n" \
"One could find this annoying in a task name."
sol = self._generate_sale_order_line(sale_order=so, product=product)
so.action_confirm()
task = sol.task_id
self.assertFalse("This is a long product description." in task.name)
self.assertFalse("It even spans multiple lines." in task.name)
self.assertFalse("One could find this annoying in a task name." in task.name)
self.assertTrue("It even spans multiple lines." in task.description)
self.assertTrue("One could find this annoying in a task name."
in task.description)
@tagged("-at_install", "post_install", "slow")
class TestSaleOrderTour(HttpCase, TestSalesOrder):