Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2710 Widoki

Como evito que al cargar un archivo de excel para res.partners los duplique, ya anexe llave y sigue duplicando

Awatar
Odrzuć
Najlepsza odpowiedź

To avoid duplicating an Excel file for res.partners in Odoo/OpenERP when attaching a key, you can follow these steps:

1. Check for existing attachments: Before attaching the Excel file, verify if there are already existing attachments for the res.partner records. You can do this by searching for attachments related to the specific res.partner record.

2. Update existing attachment: If there is already an attachment for the res.partner record, you can update the existing attachment instead of creating a new one. To do this, you need to access the existing attachment record and update its content with the new Excel file.

3. Create a new attachment: If there are no existing attachments for the res.partner record, then you can proceed with creating a new attachment. Make sure to set the key or unique identifier to avoid duplication.

Here's an example of how you can achieve this in Odoo/OpenERP:

```python
# Assuming you have the res.partner record and the Excel file path

# Check for existing attachments
existing_attachment = self.env['ir.attachment'].search([
('res_model', '=', 'res.partner'),
('res_id', '=', partner_id),
('name', '=', 'Your Excel File Name.xlsx')
], limit=1)

if existing_attachment:
# Update existing attachment with the new file content
with open('path/to/new/excel/file.xlsx', 'rb') as file:
existing_attachment.write({
'datas': base64.b64encode(file.read()),
})
else:
# Create a new attachment
with open('path/to/new/excel/file.xlsx', 'rb') as file:
attachment = self.env['ir.attachment'].create({
'name': 'Your Excel File Name.xlsx',
'res_model': 'res.partner',
'res_id': partner_id,
'datas': base64.b64encode(file.read()),
})
```

Make sure to replace `'Your Excel File Name.xlsx'` with the actual name of your Excel file, and `'path/to/new/excel/file.xlsx'` with the appropriate file path.

By checking for existing attachments and updating them when necessary, you can avoid duplicating the Excel file for res.partner records in Odoo/OpenERP.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
paź 23
1514
2
sie 24
1361
3
paź 24
2209
0
sie 24
997
2
paź 23
4801