Skip to content

Instantly share code, notes, and snippets.

@em230418
Created March 11, 2024 07:59
Show Gist options
  • Save em230418/d958fddeaa85b7cc31be98047bf4cfff to your computer and use it in GitHub Desktop.
Save em230418/d958fddeaa85b7cc31be98047bf4cfff to your computer and use it in GitHub Desktop.
product_id to selection
- if "project_expense_type" in res and "selection" in attributes:
- self.env.cr.execute(
- f"""
-SELECT DISTINCT t.project_expense_type
-FROM {self._table} t
-LEFT JOIN product_product p ON p.id = t.project_expense_type
-LEFT JOIN product_template pt ON pt.id = p.product_tmpl_id
-WHERE project_expense_type IS NOT NULL
- """
- )
- get_product_name = lambda x: self.env["product.product"].browse(x).name
-
- selections = [(x[0], get_product_name(x[0])) for x in self.env.cr.fetchall()]
- res["project_expense_type"].update(
- {
- "type": "selection",
- "selection": selections,
- }
- )
- print(selections)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment