odoo2odoo idea<

This commit is contained in:
Benoît Vézina 2024-03-09 08:01:09 -05:00
parent 8aa1dfdc4b
commit 41943da18f
8 changed files with 180 additions and 2 deletions

View file

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<!-- Héritage de la vue formulaire du projet pour ajuster les champs de synchronisation -->
<record id="view_project_project_form_inherit_sync" model="ir.ui.view">
<field name="name">project.project.form.inherit.sync.odoo17</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project"/>
<field name="arch" type="xml">
<xpath expr="//sheet" position="inside">
<!-- Ajout d'un nouveau séparateur pour les champs de synchronisation -->
<group string="Synchronisation Odoo">
<field name="customer_odoo_server"/>
<field name="customer_username" invisible="customer_odoo_server == False"/>
<field name="customer_password" invisible="customer_odoo_server == False"/>
</group>
</xpath>
</field>
</record>
</data>
</odoo>

View file

@ -0,0 +1,10 @@
<record id="cron_sync_projects" model="ir.cron">
<field name="name">Synchroniser les Projets avec Bébé</field>
<field name="model_id" ref="model_project_project"/>
<field name="state">code</field>
<field name="code">model.sync_projects_with_baby()</field>
<field name="interval_number">1</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="active">True</field>
</record>

View file

@ -0,0 +1 @@
from . import project_project

View file

@ -0,0 +1,47 @@
from odoo import models, fields, api
class Odoo2OdooSync(models.Model):
_name = 'odoo2odoo.sync'
_description = 'Synchronisation Odoo à Odoo'
model_id = fields.Many2one(
comodel_name='ir.model',
string='Modèle Cible',
required=True,
help="Le modèle Odoo cible de la synchronisation."
)
res_id = fields.Integer(
string='ID Ressource',
required=True,
help="L'ID de la ressource cible dans le modèle spécifié."
)
json_rpc_request = fields.Text(
string='Requête JSON RPC',
required=True,
help="Le corps complet de la requête JSON RPC pour la synchronisation."
)
state = fields.Selection(
selection=[
('draft', 'Brouillon'),
('success', 'Succès'),
('failed', 'Échoué')
],
string='État',
default='draft',
required=True,
help="L'état de la tentative de synchronisation."
)
last_attempt = fields.Datetime(
string='Dernière Tentative',
help="La date et l'heure de la dernière tentative de synchronisation."
)
confirmation = fields.Datetime(
string='Confirmation',
help="La date et l'heure de la confirmation de la synchronisation réussie."
)

View file

@ -0,0 +1,92 @@
from odoo import models, fields, api
class Project(models.Model):
_inherit = 'project.project' # Héritage du modèle projet existant
customer_project_id = fields.Integer(
string="ID Projet Client",
required=False,
help="L'ID du projet dans le système client."
)
customer_odoo_server = fields.Char(string="Serveur Odoo Client")
customer_username = fields.Char(string="Nom d'usager Client")
customer_password = fields.Char(string="Mot de passe Client", invisible=True)
odoo2odoo_sync_ids = fields.One2many(
comodel_name='odoo2odoo.sync',
inverse_name='project_id',
string='Synchronisations'
)
last_push = fields.Datetime(
string="Dernière Tentative de Synchronisation",
compute="_compute_sync_status",
store=True
)
last_push_completed = fields.Datetime(
string="Dernière Synchronisation Réussie",
compute="_compute_sync_status",
store=True
)
last_updated = fields.Datetime(
string="Dernière Mise à Jour par Bébé",
ompute="_compute_sync_status",
store=True
)
odoo2odoo_sync_count = fields.Integer(
string="Nombre de Synchronisations",
compute="_compute_sync_status"
)
odoo2odoo_sync_completed_count = fields.Integer(
string="Nombre de Synchronisations Réussies",
compute="_compute_sync_status"
)
@api.model
def create(self, vals):
# Appel de la méthode super() pour créer le projet dans Odoo.
new_project = super(Project, self).create(vals)
if 'customer_odoo_server' in vals and vals['customer_odoo_server']:
# Simulation de données pour la synchronisation avec le système "bébé".
# Vous adapterez cette partie selon votre logique spécifique de synchronisation.
json_rpc_request = json.dumps({
"jsonrpc": "2.0",
"method": "create_project",
"params": {
"name": new_project.name,
# Ajoutez d'autres paramètres nécessaires pour la création du projet dans le système "bébé".
},
})
# Création d'un enregistrement dans odoo2odoo.sync pour suivre la tentative de synchronisation.
self.env['odoo2odoo.sync'].create({
'model_id': self.env.ref('base.model_project_project').id,
'res_id': new_project.id,
'json_rpc_request': json_rpc_request,
'state': 'draft', # Commencez avec l'état 'draft' pour la nouvelle synchronisation.
})
return new_project
@api.depends('odoo2odoo_sync_ids.state')
def _compute_sync_status(self):
for project in self:
sync_records = self.env['odoo2odoo.sync'].search([
('model_id.model', '=', 'project.project'),
('res_id', '=', project.id),
], order='last_attempt desc')
project.odoo2odoo_sync_count = len(sync_records)
if sync_records:
project.odoo2odoo_sync_completed_count = len(sync_records.filtered(lambda r: r.state == 'success'))
project.last_push = sync_records[0].last_attempt
success_records = sync_records.filtered(lambda r: r.state == 'success')
if success_records:
project.last_push_completed = success_records[0].last_attempt
# Assume that 'last_updated' reflects the last successful pull from 'bébé'
# This requires additional logic to track when updates are received from the bébé system
project.last_updated = success_records[0].confirmation if success_records else False

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
</data>
</odoo>

View file

@ -60,10 +60,10 @@
<xpath expr="//kanban" position="inside">
<field name="odoo_partner_type"/>
</xpath>
<xpath expr="//div[@class='oe_kanban_global_click o_kanban_record_has_image_fill o_res_partner_kanban']" position="attributes">
<xpath expr="//div[hasclass('oe_kanban_global_click') and hasclass('o_kanban_record_has_image_fill') and hasclass('o_res_partner_kanban')]" position="attributes">
<attribute name="t-attf-class">oe_kanban_global_click o_kanban_record_has_image_fill o_res_partner_kanban oe_kanban_color_#{record.color}</attribute>
</xpath>
<xpath expr="//strong[@class='o_kanban_record_title oe_partner_heading']" position="before">
<xpath expr="//strong[hasclass('o_kanban_record_title') and hasclass('oe_partner_heading')]" position="before">
<strong t-if="record.odoo_partner_type.raw_value" class="o_kanban_record_subtitle oe_partner_heading">
<field name="odoo_partner_type"/>
</strong>