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')
|
customer_ids = fields.One2many('woo.customer', 'instance_id')
|
||||||
sync_log_ids = fields.One2many('woo.sync.log', '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')
|
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(
|
excluded_category_ids = fields.Many2many(
|
||||||
'product.category', string='Hidden Categories',
|
'product.category', string='Hidden Categories',
|
||||||
help='Products in these categories will be hidden from the unmatched products list.'
|
help='Products in these categories will be hidden from the unmatched products list.'
|
||||||
@@ -183,6 +185,49 @@ class WooInstance(models.Model):
|
|||||||
break
|
break
|
||||||
return True
|
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):
|
def _get_client(self):
|
||||||
"""Return a WooApiClient instance for this WooCommerce connection."""
|
"""Return a WooApiClient instance for this WooCommerce connection."""
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class WooTaxMap(models.Model):
|
|||||||
_description = 'WooCommerce Tax Mapping'
|
_description = 'WooCommerce Tax Mapping'
|
||||||
|
|
||||||
instance_id = fields.Many2one('woo.instance', required=True, ondelete='cascade')
|
instance_id = fields.Many2one('woo.instance', required=True, ondelete='cascade')
|
||||||
tax_id = fields.Many2one('account.tax', required=True)
|
tax_id = fields.Many2one('account.tax', string='Odoo Tax')
|
||||||
woo_tax_class = fields.Char(required=True)
|
woo_tax_class = fields.Char(required=True)
|
||||||
woo_tax_class_name = fields.Char()
|
woo_tax_class_name = fields.Char()
|
||||||
company_id = fields.Many2one(
|
company_id = fields.Many2one(
|
||||||
|
|||||||
@@ -83,6 +83,27 @@
|
|||||||
<field name="sync_customers"/>
|
<field name="sync_customers"/>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
|
<separator string="Tax Mapping"/>
|
||||||
|
<div class="mb-2">
|
||||||
|
<button name="action_fetch_wc_tax_classes" type="object"
|
||||||
|
string="Fetch WC Tax Classes" class="oe_highlight"/>
|
||||||
|
</div>
|
||||||
|
<field name="tax_map_ids">
|
||||||
|
<list editable="bottom">
|
||||||
|
<field name="tax_id" string="Odoo Tax"
|
||||||
|
domain="[('type_tax_use', '=', 'sale')]"/>
|
||||||
|
<field name="woo_tax_class_name" string="WC Tax Class" readonly="1"/>
|
||||||
|
<field name="woo_tax_class" string="WC Slug" readonly="1"/>
|
||||||
|
</list>
|
||||||
|
</field>
|
||||||
|
<separator string="Pricelist Mapping"/>
|
||||||
|
<field name="pricelist_map_ids">
|
||||||
|
<list editable="bottom">
|
||||||
|
<field name="pricelist_id" string="Odoo Pricelist"/>
|
||||||
|
<field name="woo_role" string="WC Customer Role"/>
|
||||||
|
<field name="woo_role_name" string="WC Role Name"/>
|
||||||
|
</list>
|
||||||
|
</field>
|
||||||
</page>
|
</page>
|
||||||
<page string="Notifications" name="notifications">
|
<page string="Notifications" name="notifications">
|
||||||
<group>
|
<group>
|
||||||
|
|||||||
@@ -80,16 +80,6 @@
|
|||||||
action="action_woo_shipping_carrier"
|
action="action_woo_shipping_carrier"
|
||||||
sequence="20"/>
|
sequence="20"/>
|
||||||
|
|
||||||
<menuitem id="woo_menu_tax_map"
|
<!-- Tax and Pricelist mapping moved inline to Instance → Sync Settings -->
|
||||||
name="Tax Mapping"
|
|
||||||
parent="woo_menu_config"
|
|
||||||
action="action_woo_tax_map"
|
|
||||||
sequence="30"/>
|
|
||||||
|
|
||||||
<menuitem id="woo_menu_pricelist_map"
|
|
||||||
name="Price List Mapping"
|
|
||||||
parent="woo_menu_config"
|
|
||||||
action="action_woo_pricelist_map"
|
|
||||||
sequence="40"/>
|
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
Reference in New Issue
Block a user