Kenjx

Untitled

Jan 8th, 2025
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 KB | None | 0 0
  1. def action_resync(self):
  2. for rec in self:
  3. def _prepare_invoice_data(self, models, db, uid, password, move, company_id):
  4. move_lines = []
  5. partner = False
  6. for line in move.invoice_line_ids:
  7. account = line.account_id
  8. account_name_to_check = account.name
  9. if account.substitute_account:
  10. account_name_to_check = account.substitute_account.name
  11.  
  12. if account_name_to_check:
  13. account_id = self._map_account_name_to_remote_company(models, db, uid, password, company_id,
  14. account_name_to_check)
  15. remote_analytic_account_id = self._prepare_analytic_distribution(models, db, uid, password,
  16. line.analytic_account_id)
  17. tax_ids = [
  18. self._get_remote_tax_id(
  19. models, db, uid, password,
  20. 'account.tax', 'name', tax.name, move.company_id.id
  21. )
  22. for tax in line.tax_ids
  23. ]
  24. else:
  25. account_id = None
  26. remote_analytic_account_id = None
  27. tax_ids = []
  28.  
  29. move_line_data = {
  30. 'account_id': account_id,
  31. 'name': line.name,
  32. 'analytic_distribution': {
  33. str(remote_analytic_account_id): 100} if remote_analytic_account_id else {} or None,
  34. 'quantity': line.quantity or None,
  35. 'price_unit': line.price_unit or None,
  36. 'tax_ids': [(4, tax) for tax in tax_ids] if tax_ids else None,
  37. 'display_type': line.display_type if line.display_type in ['line_section',
  38. 'line_note'] else 'product',
  39. }
  40. move_lines.append((0, 0, move_line_data))
  41.  
  42. _logger.info(f"Move lines Update ******* {move_lines} ID {move.read(['name'])}")
  43. currency_id = self._get_remote_id_if_set(models, db, uid, password, 'res.currency', 'name',
  44. move.currency_id)
  45. # Ensure partner exists in remote database
  46. if move.partner_id:
  47. partner = self._get_remote_id_if_set(models, db, uid, password, 'res.partner', 'name',
  48. move.partner_id)
  49.  
  50. if not partner:
  51. raise UserError('Partner {partner} from the source is not available!')
  52.  
  53. move_data = {
  54. 'partner_id': self._get_remote_id_if_set(models, db, uid, password, 'res.partner', 'name',
  55. move.partner_id),
  56. 'patient': move.patient_id.name or None,
  57. 'payment_reference': move.payment_reference or None,
  58. 'ref': move.ref or None,
  59. 'invoice_date': move.invoice_date or None,
  60. 'invoice_date_due': move.invoice_date_due or None,
  61. 'invoice_origin': move.invoice_origin or None,
  62. 'narration': move.narration or None,
  63. 'currency_id': currency_id or None,
  64. 'invoice_line_ids': move_lines,
  65. }
  66. _logger.info(f"Moves Data -----------------------------------------\n {move_data}\n")
  67. return move_data
  68.  
  69. # Get configuration parameters
  70. config_parameters = self.env['ir.config_parameter'].sudo()
  71. remote_type = config_parameters.get_param('remote_operations.remote_type')
  72. if remote_type != 'Main Database':
  73. _logger.info(
  74. "Database is not configured as 'Main Database'. Skipping sending account moves to remote.")
  75. return
  76.  
  77. url = config_parameters.get_param('remote_operations.url')
  78. db = config_parameters.get_param('remote_operations.db')
  79. username = config_parameters.get_param('remote_operations.username')
  80. password = config_parameters.get_param('remote_operations.password')
  81.  
  82. # Validate settings
  83. if not all([url, db, username, password]):
  84. raise ValidationError("Remote server settings must be fully configured (URL, DB, Username, Password)")
  85.  
  86. # Create XML-RPC connection and send data
  87. common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url), allow_none=True)
  88. uid = common.authenticate(db, username, password, {})
  89. models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url), allow_none=True)
  90.  
  91. start_date = date(2024, 7, 1).isoformat()
  92. account_move = models.execute_kw(db, uid, password, 'account.move', 'search',
  93. [[['name', '=', rec.ref], \
  94. ['state', '=', 'posted'], ['move_type', '!=', 'entry'],
  95. ['posted_to_remote', '=', True],
  96. ['branch_id', '=', rec.company_id.id],
  97. ['date', '>=', start_date], {'limit': 1, 'order': 'date asc'}]]),
  98.  
  99. # _logger.info(
  100. # f"Account Data Moves to process......................\n {account_move.read(['name', 'posted_to_remote'])}")
  101.  
  102. # if account_move:
  103. # move_data = _prepare_invoice_data(models, db, uid, password, account_move, account_move.company_id.id)
  104. # if move_data:
  105. # new_move = models.execute_kw(db, uid, password, 'account.move', 'write', [move_data])
  106. # _logger.info(
  107. # f"----------------------------Account Data Moves Update\n{new_move}\n-------------------------")
  108. # else:
  109. # raise UserError("Could not find related invoice from the source(No Invoice Data)..")
  110. # else:
  111. # raise UserError("Could not find related invoice from the source..")
  112.  
Advertisement
Add Comment
Please, Sign In to add comment