feat: add editable WC SKU and Odoo SKU columns with bidirectional sync

Both SKU fields are inline-editable. Arrow buttons sync individual SKUs.
Bulk buttons sync all SKUs Odoo→WC or WC→Odoo.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsinghpal
2026-04-01 13:32:26 -04:00
parent 1a1a37b3e3
commit 3179cc1f7b
5 changed files with 230 additions and 12 deletions

View File

@@ -772,6 +772,30 @@ class WooInstance(models.Model):
])
maps.action_push_price_to_odoo()
# ------------------------------------------------------------------
# Bulk SKU Sync (UI actions)
# ------------------------------------------------------------------
def action_bulk_sku_odoo_to_wc(self):
"""Push all Odoo SKUs to WooCommerce."""
self.ensure_one()
maps = self.env['woo.product.map'].search([
('instance_id', '=', self.id),
('state', '=', 'mapped'),
('product_id', '!=', False),
])
maps.action_push_sku_to_wc()
def action_bulk_sku_wc_to_odoo(self):
"""Pull all WC SKUs to Odoo."""
self.ensure_one()
maps = self.env['woo.product.map'].search([
('instance_id', '=', self.id),
('state', '=', 'mapped'),
('product_id', '!=', False),
])
maps.action_push_sku_to_odoo()
# ------------------------------------------------------------------
# Product / Price Sync (Task 22)
# ------------------------------------------------------------------

View File

@@ -155,6 +155,46 @@ class WooProductMap(models.Model):
'Sale price set to $%.2f' % price,
)
# ------------------------------------------------------------------
# SKU Sync
# ------------------------------------------------------------------
def action_set_wc_sku(self, sku):
"""Set WC product SKU."""
self.ensure_one()
if not self.instance_id:
return
client = self.instance_id._get_client()
client.update_product(self.woo_product_id, {'sku': sku})
self.woo_sku = sku
self.instance_id._log_sync(
'product', 'odoo_to_woo', self.woo_product_name, 'success',
'WC SKU set to %s' % sku,
)
def action_push_sku_to_odoo(self):
"""Copy WC SKU to Odoo internal reference."""
for rec in self:
if rec.product_id and rec.woo_sku:
rec.product_id.default_code = rec.woo_sku
rec.instance_id._log_sync(
'product', 'woo_to_odoo', rec.product_id.name, 'success',
'Odoo SKU set from WC: %s' % rec.woo_sku,
)
def action_push_sku_to_wc(self):
"""Copy Odoo internal reference to WC SKU."""
for rec in self:
if rec.product_id and rec.instance_id:
sku = rec.product_id.default_code or ''
client = rec.instance_id._get_client()
client.update_product(rec.woo_product_id, {'sku': sku})
rec.woo_sku = sku
rec.instance_id._log_sync(
'product', 'odoo_to_woo', rec.product_id.name, 'success',
'WC SKU set from Odoo: %s' % sku,
)
# ------------------------------------------------------------------
# Image Sync (Task 22)
# ------------------------------------------------------------------