Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

How to unlink record from Ony2Many relation?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
one2manyunlink
6 Răspunsuri
19110 Vizualizări
Imagine profil
Muhammad Anees

Hii,

One2Many Custom Model

class PurchaseShipment(models.Model):
_name = "purchase.shipment"
    purchase_line_ids = fields.One2many('purchase.order.line', 'shipment_id', string='Shipment Lines')    ​

Many2one Purchase Order Line

class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"
shipment_id = fields.Many2one('purchase.shipment', string='Shipment', copy=False, ondelete='set null')

I have a wizard that add purchase lines to purchase.shipment table. purchase.shipment view has a page and inside I show lines in a tree and after tree there is Add Lines button that calls wizard to add lines and it works ok.

class PurchaseShipmentLines(models.TransientModel):
_name = 'purchase.shipment.lines'
_description = 'Adds/Links purchase order lines to shipment for all selected lines'
def _default_shipment(self):
return self.env['purchase.shipment'].browse(self._context.get('active_id'))
shipment_id = fields.Many2one('purchase.shipment', string="Shipment", required=True, default=_default_shipment)
purchase_order_lines = fields.Many2many('purchase.order.line', string="Purchase Order Lines")
@api.multi
def add_to_shipment(self):
self.shipment_id.purchase_line_ids |= self.purchase_order_lines
return {}

Now I want to remove/unlink line(s) from purchase.shipment line tree. By default there is delete icon on line item tree but it try to delete from purchase.order.line model. How to unlink purchase line from purchase.shipment. Odoo v12.

Thanks,


3
Imagine profil
Abandonează
Imagine profil
Sylvain Michel Ratsarafahatra
Cel mai bun răspuns

Hi,

Just change the paramater ondelete="set null" to ondelete="cascade" in your field declaration on purchase.order.line model.

CASCADE specifies that when a referenced row is deleted, row(s) referencing it should be automatically deleted as well.

shipment_id = fields.Many2one('purchase.shipment', string='Shipment', copy=False, ondelete='cascade')

Best regards

2
Imagine profil
Abandonează
Muhammad Anees
Autor

Hii Sylvain,

I changed ondelete='cascade' on purchase.order.line model as you said. What happened is when I deleted a line from purchase.shipment it deleted from purchase.order.line model as well. And that is not my requirement.

My requirement is to remove from purchase.shipment model only.

How to unlink or remove reference of One2many record from purchase.shipment.

Muhammad Anees
Autor

Here is Tree View

I want to unlink when deleting from this tree...

<field name="purchase_line_ids" nolabel="1">

<tree>

<field name="order_id" />

<field name="product_id" />

<field name="product_qty" />

<field name="qty_received" />

<field name="qty_invoiced" />

<field name="price_unit" />

</tree>

</field>

Imagine profil
Jake Robinson
Cel mai bun răspuns

Hi,

The easiest way will be to create a new button on the tree view:

<button type="object" name="action_remove_shipment" icon="fa-chain-broken" string="Remove from Shipment"/>

Then in the purchase_order_line python file, add:

def action_remove_shipment(self):
    self.write({'shipment_id': False})   ​    ​   ​

Rather than deleting the purchase order line, it will just remove the link between the line and the shipment.

2
Imagine profil
Abandonează
Muhammad Anees
Autor

Thank you Jake Robinson. This is want I was looking for. Up Vote for you.

Imagine profil
Muhammad Anees
Autor Cel mai bun răspuns

Override the child table unlink method worked for me....it will not delete the one2many record instead will remove from the one2many tree view. This method is executed on Save (edit the record will show trash/delete icon on tree, press it and delete).

@api.multi
def unlink(self): 
    self.write({'payslip_id': False})
    return True

0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
how pass value to on2many field from parent form via context
one2many
Imagine profil
Imagine profil
1
ian. 25
2718
how to delete one2many if many2one is deleted Rezolvat
many2one one2many relationship unlink
Imagine profil
Imagine profil
1
mai 23
3518
How to make tree view place last entered field on the top of tree view? What is the difference between editable="top" and editable="bottom"?
one2many
Imagine profil
Imagine profil
Imagine profil
2
sept. 22
10425
How to configure one2many field inside a form with domain or filter Rezolvat
one2many
Imagine profil
Imagine profil
2
apr. 22
5285
I got "ValueError: Invalid field 'Title' on model 'res.partner'" when I use One2many
one2many
Imagine profil
0
iul. 21
8059
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now