Skip to Content
Menu
This question has been flagged
1 Reply
873 Views

hi all iam trying to add a button which will create vendors from emplyoees , but its not working can anyone check my function below ,


    

@api.model

    def create_partner_ven(self, vals):

        emp_obj = self.env['res.partner']

        print(self.name,"NAME OF EMP --")

        emp_obj.create({

            'name': self.name,

            'supplier_rank':1,

            'customer_rank':1,

            })


when i click the button i get a popup like :

Contacts require a name


log :

odoo.http: ('Contacts require a name', None)
ERROR: new row for relation "res_partner" violates check constraint "res_partner_check_name"

Avatar
Discard
Author

anyone ?

Author

i tried like this too , same result :

@api.model

def create_partner_ven(self, vals):

emp_obj = self.env['res.partner'].browse(self._context.get('active_ids', []))

#active_id = self._context.get('current_id')

#active_id = self._context('active_ids')

print(self.name,"NAME OF EMP --")

emp_obj.create({

'name': self.name,

'supplier_rank':1,

'customer_rank':1,

})

Best Answer

The supplier_rank field is automatically managed by Odoo, you don't need to do anything. 


The first time a Vendor Bill is posted for an Employee, they automatically become a Vendor, with their supplier_rank field getting increased.

See:

https://github.com/odoo/odoo/blob/14.0/addons/account/models/partner.py#L495

This function is called during the posting of Invoices and Bills: https://github.com/odoo/odoo/blob/14.0/addons/account/models/account_move.py#L2492

Avatar
Discard
Related Posts Replies Views Activity
2
Nov 24
263
1
Oct 24
331
4
Oct 24
324
2
Oct 24
361
2
Dec 24
667