Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Información
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Food & Hospitality
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Guest House
    • Distribuidor de bebidas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consulting
    • Accounting Firm
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Trades
    • Handyman
    • Hardware y asistencia informática
    • Solar Energy Systems
    • Zapatero
    • Servicios de limpieza
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

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

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

How to transfer/reflect documents from sale.order to project.task

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
sale.orderproject.taskir.attachmentodoo16features
1 Responder
2988 Vistas
Avatar
Alark Kulkarni

How to transfer/reflect documents from sale.order to project.task model? I am unable to achieve the result with my code.

The documents should not get jumbled. If sale order S0001 contains 3 documents then the project task related to S0001 should reflect 3 documents and if sale order S0003 contains 0 documents then the project task related to S0003 should reflect 0.

Please find the xml & py code below:



# -*- coding: utf-8 -*-
from odoo import api, fields, models, _

from Odoo16_Community.odoo.odoo.exceptions import AccessError


class ProjectTask(models.Model):
_inherit = 'project.task'
_description = 'Display smart button for attachments'

sale_line_id = fields.Many2one(
'sale.order.line', 'Sales Order Item',
copy=True, tracking=True, index='btree_not_null', recursive=True, store=True, readonly=True)
sale_order_id = fields.Many2one('sale.order', 'Sales Order', store=True,
help="Sales order to which the task is linked.")

display_attachment_button = fields.Boolean(string='Display Attachments',
compute='_compute_display_attachments_button')
attachment_count = fields.Integer('Attachments Count', compute='_compute_attachment_count')
attachments = fields.Char("Attachments Name", compute='_compute_attachment_name')
attachment_ids = fields.One2many(
'ir.attachment',
'res_id',
domain=[('res_model', '=', 'sale.order')],
string='Attachments'
)

def _compute_attachment_name(self):
for rec in self:
attachments = self.env['ir.attachment'].search([('res_model', '=', 'sale.order'), ('res_id', '=', rec.id)])
rec.attachments = attachments[0].name if rec.attachment_count
def _compute_attachment_count(self):
for rec in self:
attachments = self.env['ir.attachment'].search_count(
[('res_model', '=', 'sale.order'), ('res_id', '=', rec.id)])
rec.attachment_count = attachments

@api.depends('sale_line_id')
def _compute_display_attachments_button(self):
if not self.sale_line_id:
self.display_attachment_button = False
return
try:
sale_line = self.env['sale.order.line'].search([('id', 'in', self.sale_line_id.ids)])
for task in self:
task.display_attachment_button = task.sale_line_id in sale_line
except AccessError:
self.display_attachment_button = False

def action_show_attachments(self):
return {
'name': _('Attachments'),
'view_mode': 'kanban,form',
'res_model': 'ir.attachment',
'type': 'ir.actions.act_window',
'domain': [('res_model', '=', 'sale.order'), ('res_id', '=', self.id)]
}

def action_view_so(self):
return {
"type": "ir.actions.act_window",
"res_model": "sale.order",
"name": _("Sales Order"),
"views": [[False, "tree"], [False, "kanban"], [False, "form"]],
"context": {"create": False, "show_sale": True},
}

Thank you in advance.


0
Avatar
Descartar
Avatar
Maciej Burzymowski
Mejor respuesta

To transfer documents from sale.order to project.task in Odoo, you need to create a relationship between these two models. This can be achieved by creating a One2many or Many2many field in the sale.order model that references the project.task model.

Here is a basic example of how you might set up this relationship in your models:


class SaleOrder(models.Model):

    _inherit = 'sale.order'


    task_ids = fields.One2many('project.task', 'sale_order_id', string='Tasks')


class ProjectTask(models.Model):

    _inherit = 'project.task'


    sale_order_id = fields.Many2one('sale.order', string='Sale Order')

    document_ids = fields.Many2many('ir.attachment', string='Documents')


In this example, task_ids is a One2many field that gets the tasks related to the sale order, and sale_order_id is a Many2one field that gets the sale order related to the task. document_ids is a Many2many field that gets the documents related to the task.

You can then override the create and write methods in the sale.order model to update the document_ids field in the related tasks whenever a sale order is created or updated.


0
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
Show rental orders on main Odoo Calendar module
sale.order odoo16features
Avatar
0
abr 24
933
I want to attach a static pdf file in the Sale Order Email
email sale.order ir.attachment
Avatar
0
sept 23
2377
how to set a button in email redirecting the the sales order url Resuelto
sale.order mailtemplate odoo16features
Avatar
Avatar
1
sept 23
5142
Automated Action to clone a task and adding days to due date Resuelto
project.task AutomatedActions odoo16features
Avatar
1
nov 22
3597
What types of files will be saved when defining the path for the data_dir option in odoo.conf
attachment config ir.attachment odoo16features
Avatar
Avatar
1
mar 24
4011
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة 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 es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

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