Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ivess/addons
1 result
Show changes
Commits on Source (2)
......@@ -24,6 +24,7 @@ class DeliveryRoute(models.Model):
truck_id = fields.Many2one(
'fleet.truck',
string='Truck License Plate',
domain="allowed_truck_domain"
# required=True
)
template_delivery_route_id = fields.Many2one(
......@@ -33,13 +34,11 @@ class DeliveryRoute(models.Model):
delivery_person_id = fields.Many2one(
'res.users',
string='Delivery Person',
domain="allowed_person_domain",
# required=True
)
allowed_person_ids = fields.Many2many(
comodel_name='res.users',
string="Allowed Person",
compute='_compute_allowed_person',
)
allowed_person_domain = fields.Binary(compute='_compute_allowed_person')
allowed_truck_domain = fields.Binary(compute='_compute_allowed_truck')
delivery_date = fields.Date(
string='Delivery Date',
)
......@@ -70,12 +69,21 @@ class DeliveryRoute(models.Model):
@api.depends('truck_id')
def _compute_allowed_person(self):
all_users = self.env['res.users'].search([]) # Obtiene todos los usuarios
for rec in self:
if rec.truck_id:
rec.allowed_person_ids = rec.truck_id.user_assigned_ids
domain = [('id', 'in', rec.truck_id.user_assigned_ids.ids)]
else:
domain = []
rec.allowed_person_domain = domain
@api.depends('delivery_person_id')
def _compute_allowed_truck(self):
for rec in self:
if rec.delivery_person_id:
domain = [('user_assigned_ids', 'in', rec.delivery_person_id.id)]
else:
rec.allowed_person_ids = all_users
domain = []
rec.allowed_truck_domain = domain
def _prepare_route_lines_from_template(self, template):
"""Prepara las líneas de la ruta copiándolas desde el template."""
......
......@@ -20,9 +20,10 @@
<group>
<field name="create_from_wizard" invisible="1"/>
<field name="template_delivery_route_id" required="True" readonly="state not in ('draft', 'in_progress')"/>
<field name="truck_id" required="True" readonly="state not in ('draft', 'in_progress')"/>
<field name="allowed_person_ids" invisible="1"/>
<field name="delivery_person_id" required="True" readonly="state not in ('draft', 'in_progress')" domain="[('id', 'in', allowed_person_ids)]"/>
<field name="allowed_truck_domain" invisible="1"/>
<field name="truck_id" required="True" readonly="state not in ('draft', 'in_progress')"/> <!--domain="[('id', 'in', allowed_truck_ids)]"-->
<field name="allowed_person_domain" invisible="1"/>
<field name="delivery_person_id" required="True" readonly="state not in ('draft', 'in_progress')"/> <!--domain="[('id', 'in', allowed_person_ids)]"-->
<field name="delivery_date" readonly="state not in ('draft', 'in_progress')"/>
<field name="delivery_type" readonly="state not in ('draft', 'in_progress')"/>
</group>
......