1
class DownloadReport(models.Model):
    _name = "santex.download_report"

    agency = fields.Many2one("res.partner", string="Agency",
                             domain="[('is_company', '=', True), '|' ,('company_type_santex','=','Supplier/Vendor'), ('company_type_santex','=','Supplier Agency')]")

    report = fields.Binary(string="Report")
    file_name = fields.Text(string="Name", copy=False)
    customer_auth = fields.One2many("santex.customer_auth", inverse_name="company_skills")
    licensor_auth = fields.One2many("santex.licensor_auth", inverse_name="company_skills")
    certification_auth = fields.One2many("santex.certification_auth", inverse_name="company_skills")

    @api.model
    def create(self, vals_list):
        recs_1 = self.env['santex.customer_auth'].create({'agency': vals_list["agency"]})
        recs_2 = self.env['santex.licensor_auth'].create({'agency': vals_list["agency"]})
        recs_3 = self.env['santex.certification_auth'].create({'agency': vals_list["agency"]})

        vals_list["customer_auth"] = recs_1
        vals_list["licensor_auth"] = recs_2
        vals_list["certification_auth"] = recs_3

        record = super(DownloadReport, self).create(vals_list)

        return record

For information:

    recs_1 = [santex.customer_auth(75,), santex.customer_auth(76,)]
    
    recs_2 = [santex.licensor_auth(65,), santex.licensor_auth(66,)]
    
    recs_3 = [santex.certification_auth(33,)]

Well, it seems like vals_list["customer_auth"] = rec_1 is wrong.

i am getting this error : psycopg2.ProgrammingError: can't adapt type 'santex.customer_auth'

Thanks for any help.

Muhammad Yusuf
  • 563
  • 4
  • 20

2 Answers2

1

The error you're encountering, psycopg2.ProgrammingError: can't adapt type 'santex.customer_auth', occurs because you're trying to assign a recordset (rec_1, rec_2, rec_3) to the vals_list dictionary, which is not a supported data type for the fields customer_auth, licensor_auth, and certification_auth.

You can try this to fix this:

class DownloadReport(models.Model):
    _name = "santex.download_report"

    agency = fields.Many2one("res.partner", string="Agency",
    domain="[('is_company', '=', True), '|', ('company_type_santex', '=', 'Supplier/Vendor'), ('company_type_santex', '=', 'Supplier Agency')]")

    report = fields.Binary(string="Report")
    file_name = fields.Text(string="Name", copy=False)
    customer_auth = fields.One2many("santex.customer_auth", inverse_name="company_skills")
    licensor_auth = fields.One2many("santex.licensor_auth", inverse_name="company_skills")
    certification_auth = fields.One2many("santex.certification_auth", inverse_name="company_skills")
    @api.model
    def create(self, vals_list):
        recs_1 = self.env['santex.customer_auth'].create({'agency': vals_list["agency"]})
        recs_2 = self.env['santex.licensor_auth'].create({'agency': vals_list["agency"]})
        recs_3 = self.env['santex.certification_auth'].create({'agency': vals_list["agency"]})
 
        vals_list["customer_auth"] = [(4, rec.id) for rec in recs_1]
        vals_list["licensor_auth"] = [(4, rec.id) for rec in recs_2]
        vals_list["certification_auth"] = [(4, rec.id) for rec in recs_3]
 
        record = super(DownloadReport, self).create(vals_list)
 
        return record

Thanks

  • One2many records should link automatically if you provide values as a list of commands. You can check the [channel_last_seen_partner_ids](https://github.com/odoo/odoo/blob/15.0/addons/mail/models/mail_channel.py#L888-L894) field, they didn't provide the [channel_id](https://github.com/odoo/odoo/blob/15.0/addons/mail/models/mail_channel.py#L72-L74) field in values – Kenly May 25 '23 at 10:29
1

There is no need to update the one2many fields ("customer_auth", "licensor_auth", and "certification_auth"). You just need to assign a value to the inverse field "company_skills" inside the "create" method.

    @api.model
    def create(self, vals_list):
        new_record = super(DownloadReport, self).create(vals_list)
        self.env['santex.customer_auth'].create({'agency': vals_list["agency"], 'company_skills': new_record.id})
        self.env['santex.licensor_auth'].create({'agency': vals_list["agency"], 'company_skills': new_record.id})
        self.env['santex.certification_auth'].create({'agency': vals_list["agency"], 'company_skills': new_record.id})
        return new_record
Ali Badran
  • 46
  • 4
  • What about adding the field values to ``vals_list`` and letting Odoo set the inverse field value – Kenly May 28 '23 at 08:51