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
- Účtovníctvo
- Sklady
- PoS
- Project
- MRP
This question has been flagged
1178
Zobrazenia
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Registrácia