Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

Field sales_count

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
salesproductenterprisev15
2 Odpowiedzi
3765 Widoki
Awatar
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
Awatar
Odrzuć
Awatar
Alexandre Sousa
Najlepsza odpowiedź

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
Awatar
Odrzuć
Kamran Lalehparvar
Autor

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
Autor

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.

Awatar
Farooq Rajput
Najlepsza odpowiedź

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
Awatar
Odrzuć
Farooq Rajput

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

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
How do i edit odoo default product view?
sales product odoo v15
Awatar
Awatar
Awatar
2
sty 24
4622
Conditionally show or hide product attributes (Odoo Online/Studio)
sales product
Awatar
Awatar
1
paź 25
680
Hide the cost
sales product
Awatar
Awatar
Awatar
2
maj 25
4536
Products in multi company
sales product
Awatar
0
lis 24
1528
how to filter out all products which got no sales with the last 3 months or a specific period?
sales product
Awatar
Awatar
1
sie 24
2348
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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