feat: move tax and pricelist mapping inline to Sync Settings tab
Tax mapping and pricelist mapping now live directly on the instance form under Sync Settings. Added Fetch WC Tax Classes button that pulls tax classes from WC API and auto-matches. Removed standalone menu items. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -51,8 +51,10 @@ class WooInstance(models.Model):
|
||||
customer_ids = fields.One2many('woo.customer', 'instance_id')
|
||||
sync_log_ids = fields.One2many('woo.sync.log', 'instance_id')
|
||||
|
||||
# Category mapping
|
||||
# Mappings
|
||||
category_map_ids = fields.One2many('woo.category.map', 'instance_id', string='Category Mappings')
|
||||
tax_map_ids = fields.One2many('woo.tax.map', 'instance_id', string='Tax Mappings')
|
||||
pricelist_map_ids = fields.One2many('woo.pricelist.map', 'instance_id', string='Pricelist Mappings')
|
||||
excluded_category_ids = fields.Many2many(
|
||||
'product.category', string='Hidden Categories',
|
||||
help='Products in these categories will be hidden from the unmatched products list.'
|
||||
@@ -183,6 +185,49 @@ class WooInstance(models.Model):
|
||||
break
|
||||
return True
|
||||
|
||||
def action_fetch_wc_tax_classes(self):
|
||||
"""Fetch WooCommerce tax classes for mapping."""
|
||||
self.ensure_one()
|
||||
client = self._get_client()
|
||||
TaxMap = self.env['woo.tax.map']
|
||||
try:
|
||||
tax_classes = client.get_tax_classes()
|
||||
except Exception as e:
|
||||
raise UserError('Failed to fetch WC tax classes: %s' % str(e))
|
||||
|
||||
for tc in tax_classes:
|
||||
slug = tc.get('slug', '')
|
||||
name = tc.get('name', '')
|
||||
existing = TaxMap.search([
|
||||
('instance_id', '=', self.id),
|
||||
('woo_tax_class', '=', slug),
|
||||
], limit=1)
|
||||
if existing:
|
||||
existing.woo_tax_class_name = name
|
||||
else:
|
||||
# Try to auto-match by name similarity
|
||||
odoo_tax = False
|
||||
if 'zero' in slug.lower() or 'exempt' in slug.lower():
|
||||
odoo_tax = self.env['account.tax'].search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('amount', '=', 0),
|
||||
('company_id', '=', self.company_id.id),
|
||||
], limit=1)
|
||||
elif 'standard' in slug.lower():
|
||||
odoo_tax = self.env['account.tax'].search([
|
||||
('type_tax_use', '=', 'sale'),
|
||||
('amount', '>', 0),
|
||||
('company_id', '=', self.company_id.id),
|
||||
], limit=1, order='amount desc')
|
||||
TaxMap.create({
|
||||
'instance_id': self.id,
|
||||
'tax_id': odoo_tax.id if odoo_tax else False,
|
||||
'woo_tax_class': slug,
|
||||
'woo_tax_class_name': name,
|
||||
'company_id': self.company_id.id,
|
||||
})
|
||||
return True
|
||||
|
||||
def _get_client(self):
|
||||
"""Return a WooApiClient instance for this WooCommerce connection."""
|
||||
self.ensure_one()
|
||||
|
||||
Reference in New Issue
Block a user