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

developing my first app

Abonare

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

Această întrebare a fost marcată
developement
1 Răspunde
3160 Vizualizări
Imagine profil
Wombat

Hi,

I thought id challenge myself by creating an app to pull the previous sales quantities into the product template list view. After many, many hours, unfortunately it seems I cannot work out how to do it.

I have successfully put a float field on the product.template.

Here is my model:

from odoo import api, models, fields

class ProductsSold(models.Model):
_inherit = "product.template" # database table name.

sold = fields.Float(compute='_compute_avail', string="Avail")

def _compute_avail(self):
#sold = self.env['stock.quant'].search_count([])
# records_sum = sum(self.env["stock.quant"].search([]).mapped('inventory_quantity'))
records_sum = sum(self.env["sale.sale_order_line"].search([]).mapped('product_uom_qty'))
self.sold = records_sum

If anyone can offer any hints, I'd be grateful.




0
Imagine profil
Abandonează
Wombat
Autor

Thank you for your response. Awesome!! It works perfectly.

Next challenge: I would then like to set some filters on this field to sum up the sales in the past month - which I think I can probably achieve now. 

Although, I am curious about your mention of uom. Is there something here I am overlooking?

Ray Carnes (ray)

If you ANSWER a question, the OP is notified, but nobody else. I can't convert your answer into a comment that @Fazle can see, so if you'd like to ping him, please comment on HIS answer.

Fazle Rabbi Ferdaus

Hi wombat, may I know which approach you followed?

Wombat
Autor

Hi Fazle, I when with the first version. I think the word "available" caused some confusion as I was looking for the quantity sold.
Thank you Ray. I am new to forums and their etiquette. I imagine from your response I must have hit answer instead of comment. Not sure what an OP is - or this karma thing that keeps popping up. I'll see what google can tell me.

Fazle Rabbi Ferdaus

wombat, I still advise you to go forward with the second approach

Imagine profil
Fazle Rabbi Ferdaus
Cel mai bun răspuns

Hi Wombat, this should find the qty sold for a product. Also you have to add it to the view. Again I think you should also consider uom. Another thing is there is already a field in the product template form to show the sale qty. The field is called 'sales_count'. So this funtion or a new field should be redundent. 

from odoo import api, models, fields

class ProductsSold(models.Model):
_inherit = "product.product" # database table name.

def _compute_avail(self):
records_sum = sum(self.env["sale.order.line"].search([('product_id', '=', self.id), ('state', '=', 'sale')]).mapped('product_uom_qty'))
self.sold = records_sum sold = fields.Float(compute='_compute_avail', string="Avail")

instead this below should do want you want to achive. and no need to create any field or method. in words you need to inherit the tree view and just add the sales_count field. **Code section in comment does not let me include closing tags**


product_template_inherit_treefield>
product.templatefield>





xpath>

field>
record>


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
UI All over the place
developement
Imagine profil
Imagine profil
Imagine profil
3
iun. 23
2859
How to set my test period account in my local odoo
developement
Imagine profil
Imagine profil
1
sept. 22
3293
How to read a record for each row
developement
Imagine profil
0
apr. 22
4182
How to disable the existing data suggestions when entering new one
developement
Imagine profil
Imagine profil
1
ian. 22
5079
Begenning in odoo developement
developement
Imagine profil
Imagine profil
2
oct. 16
3826
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