Como evito que al cargar un archivo de excel para res.partners los duplique, ya anexe llave y sigue duplicando
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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.
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 10 23
|
1578 | ||
|
2
thg 8 24
|
1426 | ||
|
3
thg 10 24
|
2295 | ||
|
0
thg 8 24
|
1061 | ||
|
2
thg 10 23
|
4990 |