Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Guest House
    • Drankenhandelaar
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Solar Energy Systems
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC Services
    Others
    • Nonprofit Organization
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

Field sales_count

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
salesproductenterprisev15
2 Antwoorden
3707 Weergaven
Avatar
Kamran Lalehparvar

Hi

How can i have a filed like sales_count on product.product that showing sales on last 180 days and 90 days ago instead of 365 days ago ?

thank you in advance

0
Avatar
Annuleer
Avatar
Alexandre Sousa
Beste antwoord

Hi Kamran,

You can start by creating a new smart button in the product, for that, I suggest you extend the xml of the product. 

Here is the standard xml that creates the standard button (365 days) you can use it as a base to create your own button:


model="ir.ui.view" id="product_form_view_sale_order_button">
name="name">product.product.sale.order
name="model">product.product
name="inherit_id" ref="product.product_normal_form_view"/>
name="groups_id" eval="[(4, ref('sales_team.group_sale_salesman'))]"/>
name="arch" type="xml">
name="button_box" position="inside">


name="description" position="after">
string="Warning when Selling this Product" groups="sale.group_warning_sale">
name="sale_line_warn" nolabel="1"/>
name="sale_line_warn_msg" colspan="3" nolabel="1"
attrs="{'required':[('sale_line_warn','!=','no-message')],'readonly':[('sale_line_warn','=','no-message')]}"/>





** of course you must create also your own custom field  sales_count and calculate it using a compute function

Then you just need to create a new action in the product by extending the py of the product.

Here is the standard action to open the sales of the last 365 days:


def action_view_sales(self):
action = self.env.ref('sale.report_all_channels_sales_action').read()[0]
action['domain'] = [('product_id', 'in', self.ids)]
action['context'] = {
'pivot_measures': ['product_uom_qty'],
'active_id'
: self._context.get('active_id'),
'search_default_Sales'
: 1,
'active_model'
: 'sale.report',
'time_ranges'
: {'field': 'date', 'range': 'last_365_days'},
}
return action


Here is the tricky part: if you don't calculate the domain in python you must create a new filter in the search portion of the xml, so then you can call this new filter in the action by passing its name by context.

Hope it helps you to get started.

1
Avatar
Annuleer
Kamran Lalehparvar
Auteur

Hi Alexander
Thank you for your reply unfortunately I’m not that much technical i was wondering if you make it a little more clear

Alexandre Sousa

Hi Kamran, I've included more details in the answer, hope that helps in giving you a better direction.

Kamran Lalehparvar
Auteur

Alexander
Thank you 🙏
Can i have the code for compute custom filed ? And one more thing can i use server action instead of extend py code ? If yes please kindly describe it a little more
Thank you in advance

Alexandre Sousa

Hi Kamran,
Here is the code for the field:
sales_count = fields.Float(compute='_compute_sales_count', string='Sold')
def _compute_sales_count(self):
r = {}
self.sales_count = 0
if not self.user_has_groups('sales_team.group_sale_salesman'):
return r
date_from = fields.Datetime.to_string(fields.datetime.combine(fields.datetime.now() - timedelta(days=365),
time.min))

done_states = self.env['sale.report']._get_done_states()

domain = [
('state', 'in', done_states),
('product_id', 'in', self.ids),
('date', '>=', date_from),
]
for group in self.env['sale.report'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']):
r[group['product_id'][0]] = group['product_uom_qty']
for product in self:
if not product.id:
product.sales_count = 0.0
continue
product.sales_count = float_round(r.get(product.id, 0), precision_rounding=product.uom_id.rounding)
return r

If you are still having problems modifying this I suggest you get started with the tutorials on the Odoo website.

Avatar
Farooq Rajput
Beste antwoord

in product.template

sales_count_custom = fields.Float(compute='_compute_sales_count_custom',string='90 Days Sale')


@api.depends('product_variant_ids.sales_count_custom')    def_compute_sales_count_custom(self):        for product inself:            product.sales_count_custom =float_round(sum([p.sales_count_custom for p in product.with_context(active_test=False).product_variant_ids]),precision_rounding=product.uom_id.rounding)        defaction_view_sales_custom(self):        action =self.env["ir.actions.actions"]._for_xml_id("sale.report_all_channels_sales_action")        action['domain']=[('product_id','in',self.ids)]        action['context']={            'pivot_measures':['product_uom_qty'],            'active_id':self._context.get('active_id'),            'search_default_Sales':1,            'active_model':'sale.report',            'time_ranges':{'field':'date','range':'last_90_days'},        }        return action


in view 


  <xpathexpr="//div[@name='button_box']"position="inside">                    <buttonclass="oe_stat_button"name="action_view_sales_custom"                        type="object"icon="fa-bar-chart-o"groups="sales_team.group_sale_salesman"help="Sold in the last 90 days"attrs="{'invisible': [('sale_ok', '=', False)]}">                        <divclass="o_field_widget o_stat_info">                            <spanclass="o_stat_value">                                <fieldname="sales_count_custom"widget="statinfo"nolabel="1"class="mr4"/>                                <fieldname="uom_name"/>                            span>                            <spanclass="o_stat_text">90 Daysspan>                        div>                    button>                xpath>

0
Avatar
Annuleer
Farooq Rajput

it will work for 90 days. cheers . after looking at this , you can make 180 days one aswell.

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
How do i edit odoo default product view?
sales product odoo v15
Avatar
Avatar
Avatar
2
jan. 24
4497
Conditionally show or hide product attributes (Odoo Online/Studio)
sales product
Avatar
Avatar
1
okt. 25
599
Hide the cost
sales product
Avatar
Avatar
Avatar
2
mei 25
4424
Products in multi company
sales product
Avatar
0
nov. 24
1497
how to filter out all products which got no sales with the last 3 months or a specific period?
sales product
Avatar
Avatar
1
aug. 24
2281
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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