Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
3337 Lượt xem
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"] = rec_1
vals_list["licensor_auth"] = rec_2
vals_list["certification_auth"] = rec_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, 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.






Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

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


Hope this will help you

Thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

To update a One2many field in the create method of an Odoo model, you can modify the record's One2many field values using the write method. Here's an example of how you can achieve this:

class MyModel(models.Model):
_name = 'my.model'

name = fields.Char()
my_lines = fields.One2many( 'my.model.line','model_id')

@api.model
def create(self, values):
record = super(MyModel, self).create(values)

# Update the One2many field 'my_lines' on create
lines = []
# Add your logic to generate the lines or fetch them from another source
for i in range(3):
line_values = {
'name': 'Line {}'.format(i+1),
'model_id': record.id,
}
lines.append((0, 0, line_values))

record.write({'my_lines': lines})

return record


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

The error you're encountering

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 1 22
465
3
thg 11 21
3697
2
thg 8 24
5097
1
thg 4 23
2436
1
thg 10 21
9378