Files
Odoo-Modules/fusion-woo-odoo/fusion_woocommerce/models/woo_pricelist_map.py
gsinghpal 3022b8ed59 CHANGES
2026-04-02 10:45:07 -04:00

37 lines
1.3 KiB
Python

from odoo import api, fields, models
class WooPricelistMap(models.Model):
_name = 'woo.pricelist.map'
_description = 'WooCommerce Pricelist Mapping'
_rec_name = 'woo_role_name'
instance_id = fields.Many2one('woo.instance', required=True, ondelete='cascade')
pricelist_id = fields.Many2one('product.pricelist', required=True)
woo_role = fields.Char(required=True)
woo_role_name = fields.Char()
company_id = fields.Many2one(
'res.company', required=True, default=lambda self: self.env.company,
)
# ------------------------------------------------------------------
# Lookup helper (Task 26)
# ------------------------------------------------------------------
@api.model
def get_pricelist_for_role(self, instance, wc_role):
"""Return the Odoo product.pricelist mapped to a WC customer role.
Args:
instance: woo.instance record
wc_role: WC customer role slug (e.g. 'wholesale', 'customer')
Returns:
product.pricelist record or empty recordset
"""
mapping = self.search([
('instance_id', '=', instance.id),
('woo_role', '=', wc_role),
], limit=1)
return mapping.pricelist_id if mapping else self.env['product.pricelist']