Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
970 Vistas

Hello,


I have models make appointment customer and choose appointment customer the first model has service_id and is_package I want to pass their value into the second wizard so I can create validation here is models 


def action_open_choose_appointment(self):
choose_appointment = self.env['choose.appointment.customer'].create({
'service_id': self.service_id.id if self.service_id else False,
'is_package': self.is_package,
})
return {
'type': 'ir.actions.act_window',
'res_model': 'choose.appointment.customer',
'res_id': choose_appointment.id,
'view_mode': 'form',
'target': 'new',
'context': {
'default_service_id': self.service_id.id if self.service_id else False,
'is_package': self.is_package,
},
}

i use this function in the first model and here is the second model
lass ChooseMembershipAppointment(models.TransientModel):

_inherit = ["choose.appointment.customer"]
_description = "Choose Membership for Customer"

service_id = fields.Many2one('appointment.product', string="Service")
# ('consumed_service_ids.service_id', '=', service_id)
is_package = fields.Boolean(string="Package Selected", default=False)
membership_id = fields.Many2one('customer.membership', string='Customer Membership',
domain="[('partner_id', '=', partner_id),('status','=','active'),]")
notes = fields.Text(string="Notes")
membership_package = fields.Many2one(related='membership_id.membership_package_id')
has_membership = fields.Boolean(string="Has Membership", compute='_compute_has_membership', store=False)

def some_method(self):

business_appointment = self.env['make.business.appointment'].create({})

result = business_appointment.action_open_choose_appointment()

return result


@api.model
def create(self, vals):

print("Context: %s", self.env.context)
service_id = self.env.context.get('default_service_id')
is_package = self.env.context.get('is_package')
if service_id:
print("kkkkkkkkkkkkkk")
vals['service_id'] = service_id
if is_package:
print("wooooooooooooooooooow")
vals['is_package'] = is_package
return super(ChooseMembershipAppointment, self).create(vals)


def default_get(self, fields_list):
res = super(ChooseMembershipAppointment, self).default_get(fields_list)

res['is_package'] = self.env.context.get('default_package_selected', False)
print("Context: %s", self.env.context)
partner_id = self._context.get('partner_id')


if partner_id:
memberships = self.env['customer.membership'].search([
('partner_id', '=', partner_id),
('status', '=', 'active')
], order='date_from asc', limit=1)

if memberships:
res['membership_id'] = memberships.id


return res
Avatar
Descartar
Mejor respuesta

Using context can pass and get value


Example,


  def action_open_choose_appointment(self):

    return {

        'type': 'ir.actions.act_window',

        'res_model': 'choose.appointment.customer',

        'view_mode': 'form',

        'target': 'new',

        'context': {

            'default_service_id': self.service_id.id if self.service_id else False,

            'default_is_package': self.is_package,  # Use a prefixed key

        },

    }

   

    @api.model

    def create(self, vals):

        service_id = self.env.context.get('default_service_id')

        is_package = self.env.context.get('default_is_package')  # Use the correct context key

        if service_id:

            vals['service_id'] = service_id

        if is_package is not None: 

            vals['is_package'] = is_package

        return super(ChooseMembershipAppointment, self).create(vals)   

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
oct 24
2037
0
oct 24
509
0
ago 24
972
0
jul 24
1021
0
jun 24
1002