跳至內容
選單
此問題已被標幟
1 回覆
1611 瀏覽次數


 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

頭像
捨棄