Hello. I have a wizard (transient model) that I fire from sale order. On creation, the wizard copies some values from every sale order line and saves them in a many2many field.
So the wizard is fired with the many2many values as default. Then, after the user fills some other values in the wizard, it fires a method in the sale order line, which creates a new project.project. In the project creation function, this error is produced:
Missing Record
Record does not exist or has been deleted.
(Record: project.task(91,), User: 2)
There is no error if I don't fill the many2many field with anything, or if I don't create a new project. Can anybody help?
Code:
#wizard
class ShMessageWizard(models.TransientModel):
_name = "sh.task.wizard"
_description = "Wizard To Ask Create Or Edit"
new_project = fields.Boolean("Create New Project")
task_ids = fields.Many2many('sale.order.line.task', string="Tasks")
def task_selection_type(self):
parent_id = self.env.context.get("active_id")
parent_model = self.env.context.get("active_model")
parent_record = self.env[parent_model].browse(parent_id)
if self.new_project:
parent_record.write({'project':self\.project_id\.id\}\)
\ \ \ \ \ \ parent_record\.write\(\{'proj_user_id':self\.proj_user_id\.id\}\)
\ \ \ \ \ \ parent_record\.write\(\{'project_name':self\.project_name\}\)
\ \ \ \ \
\ \ \
\ \ \ \ parent_record\.action_create_task\(\)
\#sale\ order\ extend
class\ SaleOrder\(models\.Model\):
\ \ _inherit\ =\ "sale\.order"
\ \ create_new\ =\ fields\.Boolean\("Create\ New"\)
\ \ def\ action_create\(self\):
\ \ \
\ \ \ \ \
\ \ \ \ tasks\ =\ \[\]
\ \ \ \ for\ line\ in\ self\.order_line:
\ \ \ \ \ \ for\ task_line\ in\ line\.task_lines:
\ \ \ \ \ \ \ \ tasks\.append\(task_line\.id\)
\ \ \
\ \ \ \ return\ \{
\ \ \ \ \ \ 'name':'Create\ Task',
\ \ \ \ \ \ 'res_model':\ 'sh\.task\.wizard',
\ \ \ \ \ \ 'view_mode':'form',
\ \ \ \ \ \ 'context':\ \{
\ \ \ \ \ \ \ \ 'default_task_ids':\ \[\(6,0,tasks\)\]
\ \ \ \ \ \ \},
\ \ \ \ \ \ 'view_id':self\.env\.ref\('sh_so_task\.sh_task_wizard'\)\.id,
\ \ \ \ \ \ 'target':'new',
\ \ \ \ \ \ 'type':'ir\.actions\.act_window'
\ \ \ \ \}
\ \ \ \ \ \ \
\ \ \#\ Task\ Button\ to\ create\ project
\ \ def\ action_create_task\(self\):
\ \ \ \ if\ self:
\ \ \ \ \ \ for\ data\ in\ self:
\ \ \ \ \ \ \ \ \#\ project_obj\ =\ \[\]
\ \ \ \ \ \ \ \ if\ data\.create_new:
\ \ \ \ \ \ \ \ \ \ \#\ Create\ Project
\ \ \ \ \ \ \ \ \ \ vals\ =\ \{\}
\ \ \ \ \ \ \ \ \ \ vals\.update\(\{"name":\ data\.project_name\}\)
\ \ \ \ \ \ \ \ \ \ project_obj\ =\ self\.env\["project\.project"\]\.create\(vals\)
\ \ \ \ \ \ \ \ \ \ data\.project\ = project_obj.id
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ờ
1186
Lượt xem
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ý