Files
odoo_source/addons/partner_autocomplete/models/res_partner_autocomplete_sync.py
T
Thibault DelavalléeandDavid Beguin d3c5300272 [IMP] partner_autocomplete: extract iap calls in a separate model and add a mock
In this commit we move iap functions onto a small tool model. It allows to
hide some details in a sub model. It also allows to define a mock that will
be used in tests afterwards.

LINKS

Task ID-2322455
PR #64600
PR odoo/upgrade#2086

Co-Authored-By: David Beguin <dbe@odoo.com>
Co-Authored-By: Thibault Delavallee <tde@odoo.com>
2021-02-01 13:53:59 +00:00

39 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from odoo import api, fields, models
_logger = logging.getLogger(__name__)
class ResPartnerAutocompleteSync(models.Model):
_name = 'res.partner.autocomplete.sync'
_description = 'Partner Autocomplete Sync'
partner_id = fields.Many2one('res.partner', string="Partner", ondelete='cascade')
synched = fields.Boolean('Is synched', default=False)
@api.model
def start_sync(self):
to_sync_items = self.search([('synched', '=', False)])
for to_sync_item in to_sync_items:
partner = to_sync_item.partner_id
params = {
'partner_gid': partner.partner_gid,
}
if partner.vat and partner._is_vat_syncable(partner.vat):
params['vat'] = partner.vat
_, error = self.env['iap.autocomplete.api']._request_partner_autocomplete('update', params)
if error:
_logger.error('Send Partner to sync failed: %s' % str(error))
to_sync_item.write({'synched': True})
def add_to_queue(self, partner_id):
to_sync = self.search([('partner_id', '=', partner_id)])
if not to_sync:
to_sync = self.create({'partner_id': partner_id})
return to_sync