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

Currently, develop some code for insert record into res.partner(Contact) by calling Odoo API one by one using loop.

But, i want to insert all record by single call of Odoo API 

Is this possible ?

please have a look my existing code, implements for c#

foreach (var loCustomer in loCustomeresList)

{

    if (!string.IsNullOrEmpty(loCustomer.lsName))

    {

        loRecordPairCompany = new XmlRpcStruct();

        loRecordPairCompany.Add("name", loCustomer.lsCustomerID);

        loRecordPairCompany.Add("Phone_Number", loCustomer.lsPhoneNumber);

        loRecordPairCompany.Add("email", loCustomer.lsEmail);

        loRecordPairCompany.Add("website", loCustomer.lsWebsite);

        loRecordPairCompany.Add("property_payment_term_id", loCustomer.liCustomerPaymentTerm);

        loRecordPairCompany.Add("is_company", true);

        int liCompanyID = loRpcRecord.create(Common.lsDbName, liUserid, Common.lsDbPassword, "res.partner", "create", loRecordPairCompany);

}

}


Avatar
Discard
Best Answer

Hi Ghanshyam,

Create method only accept single dictionary to create a single record at a time. But you can create your own method in your custom module in Odoo, that will accept the list of dictionary from C#. In that method, you can loop for the list of dictionary and then call the create method.

EX:

Class ResPartner(models.Model):
    _inherit = 'res.partner'

    @api.model
    def create_multi(self, list_vals):
        # list_vals: list of dictionary [{}, {}, {}.....]
        rec_ids = []
        for val in list_vals:
            # Call create method of current object (res.partner)
            rec_ids.append(self.create(val).id)
        # Return list of IDs
        return rec_ids

Hope this will help you.

Sudhir Arya
ERP Harbor Consulting Services
Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
Avatar
Discard
Related Posts Replies Views Activity
2
Jul 24
12607
1
Jul 21
6668
0
Apr 20
3413
1
May 18
2145
0
Apr 18
2497