Skip to content

Commit

Permalink
[FIX] filter allowed UOM on project since for now only 2 uom are impl…
Browse files Browse the repository at this point in the history
…emented + default uom is empty if value on product is not allowed
  • Loading branch information
florian-dacosta committed Jan 13, 2024
1 parent a1e47b0 commit 4aa251d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
26 changes: 18 additions & 8 deletions project_invoicing_subcontractor/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
class ProjectProject(models.Model):
_inherit = "project.project"

def _get_allowed_uom_ids(self):
return [
self.env.ref("uom.product_uom_hour").id,
self.env.ref("uom.product_uom_day").id,
]

def _get_force_uom_id_domain(self):
return [("category_id", "=", self.env.ref("uom.uom_categ_wtime").id)]
return [("id", "in", self._get_allowed_uom_ids())]

invoicing_typology_id = fields.Many2one(
"project.invoice.typology", check_company=True
Expand All @@ -20,7 +26,7 @@ def _get_force_uom_id_domain(self):
help="If empty, the unit of measure will be taken on the product use for "
"invoicing (usuallly in day)",
)
uom_id = fields.Many2one("uom.uom", compute="_compute_uom_id")
uom_id = fields.Many2one("uom.uom", compute="_compute_uom_id", store=True)
hour_uom_id = fields.Many2one(
help="The default hour uom considers there are 8H in a day of work. If it is "
"different for your project, choose an other uom with a different "
Expand Down Expand Up @@ -59,12 +65,16 @@ def _get_force_uom_id_domain(self):
@api.depends("force_uom_id", "invoicing_typology_id")
def _compute_uom_id(self):
for project in self:
uom = (
project.force_uom_id
or project.invoicing_typology_id.product_id.uom_id
or False
)
project.uom_id = uom and uom.id or False
if project.force_uom_id:
uom_id = project.force_uom_id.id
elif (
project.invoicing_typology_id.product_id.uom_id.id
in self._get_allowed_uom_ids()
):
uom_id = project.invoicing_typology_id.product_id.uom_id.id
else:
uom_id = False
project.uom_id = uom_id

def _get_sale_price_unit(self):
self.ensure_one()
Expand Down
3 changes: 2 additions & 1 deletion project_invoicing_subcontractor/views/project_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
<field
name="uom_id"
string="Default Invoice uom"
attrs="{'invisible': [('force_uom_id', '!=', False)]}"
attrs="{'invisible': ['|', ('force_uom_id', '!=', False), ('uom_id', '=', False)]}"
/>
<field
name="force_uom_id"
string="Force Invoice uom"
attrs="{
'invisible': [('invoicing_typology_id', '=', False)],
'required': [('uom_id', '=', False)]
}"
/>
<field
Expand Down

0 comments on commit 4aa251d

Please sign in to comment.