Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3 Răspunsuri
5425 Vizualizări

Help, my code only creates one record. What I'm doing worng? Could anyone pls. help me?

class PartnerTagCreate(models.TransientModel):

    """ Choose tags to be added to partner."""
    _name = 'partner.tags.create'
    _description = __doc__

    market_id = fields.Many2one('partner.tags', string='Market Tag')
    application_id = fields.Many2one('partner.tags', string='Application Tag')
    partner_id = fields.Integer()
               
    @api.multi
    def create_contact_tag(self):
        
        for record in self.env['sale.order.line'].browse(self._context.get('active_ids', [])):
       
            vals = {}
            vals['partner_id'] = record.order_partner_id
           
            self.write(vals)
            return True


Thank you for your help

Paul

Imagine profil
Abandonează

Which record you wants to create?

Cel mai bun răspuns

Hello Daniela,

You can write as following :

@api.multi
def create_contact_tag(self):
order_lines = self.env['sale.order.line'].browse(self._context.get('active_ids', []))
for line in order_lines:
vals = {}
if self.name_market :
vals.update({'market_tag_ids':[(4,self.name_market.id)]})
if self.name_application :
vals.update({'application_tag_ids':[(4,self.name_application.id)]})
if vals :
line.order_partner_id.write(vals)

Thanks,

Imagine profil
Abandonează
Autor

Sorry but this doesn't work for me. I still get one record with the market_tag_id and the application_tag_id and then one ore more records for the partner_ids.

Hello Daniela,

Can you show me how are you processing it?

Autor

Could you pls. explain waht you mean by "processing it"?

Autor Cel mai bun răspuns

In the first step I want to create one rcord for each order_partner_id. For example I selected five sale_order_lines and these belong to three orders to three different customers then I want to create three records with the selected tag id's (either market tag and/or application tag) and the partner_id's.

In the next step I want to create records in my relation tables (partner_tags_market_tag_rel and partner_tags_application_tag_rel). But this is the second step. I would be really glad when I can manage the first step and konw how to manage the second step (as far as I understand I have to create records by sql injection because relation tables are not in the ORM model).

Imagine profil
Abandonează