Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.0 kB
6
Indexable
Never
class SaleOrder(models.Model):
    _inherit = "sale.order"
    _name = 'sale.order'
    _description = 'Sale Order'

    stockitems_cat1 = fields.Selection(selection=lambda self: self._get_category_options()[0], string='Category 1')
    stockitems_cat2 = fields.Selection(selection=lambda self: self._get_category_options()[1], string='Category 2')
    stockitems_cat3 = fields.Selection(selection=lambda self: self._get_category_options()[2], string='Category 3')
    stockitems_subtype = fields.Selection(selection=lambda self: self._get_category_options()[3], string='Item Subtype')
    stockitems_type = fields.Selection(selection=lambda self: self._get_category_options()[4], string='Item Type')
    brand = fields.Selection(selection=lambda self: self._get_category_options()[5], string='Brand')

    def _get_category_options(self):
        """Get the list of distinct category options from the product_categories table."""
        self.env.cr.execute("SELECT DISTINCT stockitems_category1 FROM product_categories")
        category1 = [(row[0], row[0]) for row in self.env.cr.fetchall()]
        self.env.cr.execute("SELECT DISTINCT stockitems_category2 FROM product_categories")
        category2 = [(row[0], row[0]) for row in self.env.cr.fetchall()]
        self.env.cr.execute("SELECT DISTINCT stockitems_category3 FROM product_categories")
        category3 = [(row[0], row[0]) for row in self.env.cr.fetchall()]
        self.env.cr.execute("SELECT DISTINCT stockitems_subtype FROM product_categories")
        subtype = [(row[0], row[0]) for row in self.env.cr.fetchall()]
        self.env.cr.execute("SELECT DISTINCT stockitems_type FROM product_categories")
        item_type = [(row[0], row[0]) for row in self.env.cr.fetchall()]
        self.env.cr.execute("SELECT DISTINCT brand FROM product_categories")
        brand = [(row[0], row[0]) for row in self.env.cr.fetchall()]
        return category1, category2, category3, subtype, item_type, brand