This commit is contained in:
gsinghpal
2026-05-30 20:59:59 -04:00
parent 55da42e91f
commit 5c1f60b3b8
17 changed files with 147 additions and 56 deletions

View File

@@ -4,7 +4,7 @@
{
'name': 'Fusion Inventory',
'version': '19.0.1.0.0',
'version': '19.0.1.1.0',
'category': 'Inventory',
'summary': 'Advanced inventory management with margin tracking, sync, portal sheet, and inter-company transfers',
'description': """

View File

@@ -72,15 +72,24 @@ class FusionSyncConfig(models.Model):
# ── XML-RPC Connection ──
def _get_xmlrpc_connection(self):
def _get_xmlrpc_connection(self, force=False):
self.ensure_one()
url = self.url.rstrip('/')
try:
models_proxy = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/object', allow_none=True)
# Reuse the cached uid to skip the authenticate() handshake — each
# authenticate writes a login-audit row on the remote. execute_kw
# still re-checks the API key on every call, so this stays secure.
# force=True forces a fresh authenticate (Test Connection / manual
# inter-company ops, which must work even if the cache went stale).
if self.remote_uid and not force:
return self.remote_uid, models_proxy
common = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/common', allow_none=True)
uid = common.authenticate(self.db_name, self.username, self.api_key, {})
if not uid:
raise UserError('Authentication failed. Check username/API key.')
models_proxy = xmlrpc.client.ServerProxy(f'{url}/xmlrpc/2/object', allow_none=True)
if uid != self.remote_uid:
self.sudo().write({'remote_uid': uid})
return uid, models_proxy
except xmlrpc.client.Fault as e:
raise UserError(f'XML-RPC error: {e.faultString}')
@@ -92,7 +101,7 @@ class FusionSyncConfig(models.Model):
def action_test_connection(self):
self.ensure_one()
try:
uid, models_proxy = self._get_xmlrpc_connection()
uid, models_proxy = self._get_xmlrpc_connection(force=True)
version_info = xmlrpc.client.ServerProxy(
f'{self.url.rstrip("/")}/xmlrpc/2/common', allow_none=True
).version()
@@ -174,6 +183,9 @@ class FusionSyncConfig(models.Model):
'state': 'error',
'last_sync': fields.Datetime.now(),
'last_sync_status': error_msg,
# Drop the cached uid so the next run re-authenticates fresh
# (the failure may have been a stale/invalid cached uid).
'remote_uid': False,
})
self.env['fusion.sync.log'].create({
'config_id': self.id,
@@ -544,7 +556,7 @@ class FusionSyncConfig(models.Model):
def _create_remote_sale_order(self, product_mapping, qty, partner_name):
"""Create a sale order on the remote instance for inter-company transfers."""
self.ensure_one()
uid, models_proxy = self._get_xmlrpc_connection()
uid, models_proxy = self._get_xmlrpc_connection(force=True)
partners = models_proxy.execute_kw(
self.db_name, uid, self.api_key,
@@ -593,7 +605,7 @@ class FusionSyncConfig(models.Model):
def _create_remote_invoice(self, remote_so_id):
"""Create and post an invoice for a remote sale order."""
self.ensure_one()
uid, models_proxy = self._get_xmlrpc_connection()
uid, models_proxy = self._get_xmlrpc_connection(force=True)
models_proxy.execute_kw(
self.db_name, uid, self.api_key,