
from openerp import models, fields, api, _, exceptions


class AccountTax(models.Model):
    _inherit = 'account.tax'

    @api.model
    def _get_sales_channel_domain(self):
        ids = self.env.ref('res_partner_category.sales_channel').ids
        return [('category_id', 'in', ids)]

    sales_channel_id = fields.Many2one('res.partner', string="Sales channel",
                                       ondelete='set null', domain=_get_sales_channel_domain)


from openerp import models, fields, api, _, exceptions


class AccountTax(models.Model):
    _inherit = 'account.tax'

    @api.model
    def _get_sales_channel_domain(self):
        ids = self.env.ref('res_partner_category.sales_channel').ids
        return [('category_id', 'in', ids)]

    sales_channel_id = fields.Many2one('res.partner', string="Sales channel",
                                       ondelete='set null', domain=_get_sales_channel_domain)

    _sql_constraints = [
        ('name_company_uniq', 'unique(name, company_id, sales_channel_id)', 'Tax Name must be unique per company and sales channel!'),
    ]

Add constraint, tax name must be unique for each company and sales channel
[IMP] Add constraint, tax name must be unique for each company and sales channel

  
  from openerp import models, fields, api, _, exceptions
  
  
  class AccountTax(models.Model):
      _inherit = 'account.tax'
  
      @api.model
      def _get_sales_channel_domain(self):
          ids = self.env.ref('res_partner_category.sales_channel').ids
          return [('category_id', 'in', ids)]
  
      sales_channel_id = fields.Many2one('res.partner', string="Sales channel",
                                         ondelete='set null', domain=_get_sales_channel_domain)
  
+     _sql_constraints = [
+         ('name_company_uniq', 'unique(name, company_id, sales_channel_id)', 'Tax Name must be unique per company and sales channel!'),
+     ]
+ 
Add constraint, tax name must be unique for each company and sales channel
## Code Before:

from openerp import models, fields, api, _, exceptions


class AccountTax(models.Model):
    _inherit = 'account.tax'

    @api.model
    def _get_sales_channel_domain(self):
        ids = self.env.ref('res_partner_category.sales_channel').ids
        return [('category_id', 'in', ids)]

    sales_channel_id = fields.Many2one('res.partner', string="Sales channel",
                                       ondelete='set null', domain=_get_sales_channel_domain)

## Instruction:
Add constraint, tax name must be unique for each company and sales channel
## Code After:

from openerp import models, fields, api, _, exceptions


class AccountTax(models.Model):
    _inherit = 'account.tax'

    @api.model
    def _get_sales_channel_domain(self):
        ids = self.env.ref('res_partner_category.sales_channel').ids
        return [('category_id', 'in', ids)]

    sales_channel_id = fields.Many2one('res.partner', string="Sales channel",
                                       ondelete='set null', domain=_get_sales_channel_domain)

    _sql_constraints = [
        ('name_company_uniq', 'unique(name, company_id, sales_channel_id)', 'Tax Name must be unique per company and sales channel!'),
    ]
