Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
1618 Представления


 I used this code to remove spaces on the phone in clients

 But I want to modify the customer numbers that already exist. The code is only applied to the customers that we enter recently after add code


class ResPartner(models.Model): 

   _inherit = 'res.partner'
    @api.onchange("phone") 

   def remove_spaces_from_phone_number(self):   

    for record in self:       

     if record.phone:      

          record.phone = record.phone.replace(" ", "")


    @api.onchange("mobile")  

     def remove_spaces_from_mobile_number(self):  

      for record in self:       

            if record.mobile:        

               record.mobile = record.mobile.replace(" ", "")
  
    @api.model   

    def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):           args = args or []    

      domain = []     

      if name:       

      domain = ['|', '|', ('name', operator, name), ('mobile', operator, name), ('phone', operator, name)]
        return self._search(domain + args, limit=limit, access_rights_uid=name_get_uid)
     

Аватар
Отменить

@api.onchange("phone")
def remove_spaces_from_phone_number(self):
partner_ids = self.env['res.partner'].search([('phone','!=', False)])
for record in partner_ids:
if record.phone:
record.phone = record.phone.replace(" ", "")

please use the above code for modifying the customer numbers that already exist.after running this you can use your code.

Автор

apper message

Validation Error

Similiar Value already exists in this partners

Лучший ответ

Hi,

Create a button in the Contact module where on clicking it updates the phone numbers of Existing Records .

Let the button be update_existing_phone_numbers:

<button name="update_existing_phone_numbers" string="Update Phone Numbers" type="object" class="oe_highlight" />


in.py

def update_existing_phone_numbers(self):

    partners = self.search([])  # Fetch all partners

    for partner in partners:

        if partner.phone:

            partner.phone = partner.phone.replace(" ", "")

        if partner.mobile:

            partner.mobile = partner.mobile.replace(" ", "")


Hope it helps

Аватар
Отменить