Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita 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
  • Proyectos
  • 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
3009 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.

Registrarse
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
2383
how to set a button in email redirecting the the sales order url Resuelto
sale.order mailtemplate odoo16features
Avatar
Avatar
1
sept 23
5149
Automated Action to clone a task and adding days to due date Resuelto
project.task AutomatedActions odoo16features
Avatar
1
nov 22
3606
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
4030
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • 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 estar 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