Skip to content
Extraits de code Groupes Projets
Valider 7dd23c8a rédigé par Juliana's avatar Juliana
Parcourir les fichiers

[UPD]Update copyclipboard function

parent 4ab0d4f0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -4,13 +4,10 @@ ...@@ -4,13 +4,10 @@
import logging import logging
from collections import defaultdict from collections import defaultdict
import pyperclip
from odoo import api, fields, models from odoo import api, fields, models
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
# ADDRESS_FIELDS = ('street', 'street2', 'zip', 'city')
class ResPartner(models.Model): class ResPartner(models.Model):
_inherit = "res.partner" _inherit = "res.partner"
...@@ -109,6 +106,7 @@ class ResPartner(models.Model): ...@@ -109,6 +106,7 @@ class ResPartner(models.Model):
contact_address_simple = fields.Char( contact_address_simple = fields.Char(
compute="_compute_contact_address_simple", string="Adresse simplifiée") compute="_compute_contact_address_simple", string="Adresse simplifiée")
fields_to_copy_to_clipboard = fields.Char("Champs à copier", compute="_compute_copy_to_clipboard", )
# ------------------------------------------------------ # ------------------------------------------------------
# SQL Constraints # SQL Constraints
# ------------------------------------------------------ # ------------------------------------------------------
...@@ -120,6 +118,13 @@ class ResPartner(models.Model): ...@@ -120,6 +118,13 @@ class ResPartner(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
# Computed fields / Search Fields # Computed fields / Search Fields
# ------------------------------------------------------ # ------------------------------------------------------
def _compute_copy_to_clipboard(self):
for record in self:
res = (record.lastname or "") + " " + (record.firstname or "") + "\n" + (record.street or "") + "\n" + (record.street2 or "") + "\n" + (record.street3 or "") + "\n" + (record.zip or "") + " " + (record.city or "") + "\n" + (record.parent_id.name or "") + "\n" + (record.mobile or "") + "\n" + (record.email or "")
while "\n\n" in res:
res = res.replace("\n\n", "\n")
record.fields_to_copy_to_clipboard = res.lstrip()
@api.model @api.model
def _get_default_address_format_simple(self): def _get_default_address_format_simple(self):
return "%(street)s\n%(street2)s\n%(street3)s\n%(city)s %(zip)s" return "%(street)s\n%(street2)s\n%(street3)s\n%(city)s %(zip)s"
...@@ -262,10 +267,6 @@ class ResPartner(models.Model): ...@@ -262,10 +267,6 @@ class ResPartner(models.Model):
# ------------------------------------------------------ # ------------------------------------------------------
# Actions # Actions
# ------------------------------------------------------ # ------------------------------------------------------
def copy_to_clipboard(self):
for record in self:
text_to_copy = (record.lastname or "") + " " + (record.firstname or "") + "\n" + (record.street or "") + "\n" + (record.street2 or "") + "\n" + (record.zip or "") + " " + (record.city or "") + "\n" + (record.parent_id.name or "") + "\n" + (record.mobile or "") + "\n" + (record.email or "")
pyperclip.copy(text_to_copy)
# ------------------------------------------------------ # ------------------------------------------------------
# Business methods # Business methods
......
...@@ -262,17 +262,6 @@ ...@@ -262,17 +262,6 @@
<field name="inherit_id" ref="base.view_partner_form" /> <field name="inherit_id" ref="base.view_partner_form" />
<field name="priority">100</field> <field name="priority">100</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//sheet" position="before">
<header>
<button
string="Copier les infos du contact"
name="copy_to_clipboard"
type="object"
class="oe_highlight"
attrs="{'invisible': [('parent_id', '=', False)]}"
/>
</header>
</xpath>
<xpath expr="//div[@name='button_box']" position="after"> <xpath expr="//div[@name='button_box']" position="after">
<div <div
class="alert alert-warning" class="alert alert-warning"
...@@ -350,6 +339,11 @@ ...@@ -350,6 +339,11 @@
<group name="alert" class="oe_edit_only"> <group name="alert" class="oe_edit_only">
<field name="alert" /> <field name="alert" />
</group> </group>
<group>
<div>
<field name="fields_to_copy_to_clipboard" widget="CopyClipboardChar" options="{'string': 'Copier les données'}"/>
</div>
</group>
</xpath> </xpath>
<!-- Person --> <!-- Person -->
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter