Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Update the discount in POS order

Odebírat

Get notified when there's activity on this post

This question has been flagged
Odoo17
1899 Zobrazení
Avatar
jenan soliman

Hello,

I have membership model that have consumed discount ids having consumed times and remaining times  and discount in POS when add the product, and it has discount the discount applied based in the remain times however I update the remaining times when I create the payment not when I add line because if I add lines remove I can not retrieve it back I want to another logic to achieve this  here's my function 

class Partner(models.Model):
_inherit = 'res.partner'

customer_membership_ids = fields.One2many('customer.membership', 'partner_id', string='Customer Memberships')

def get_free_service_discount_for_product(self, product_id, categ_id, line_qty, pricelist_id,order_lines,appointment_id=None,):
product = self.env['product.product'].browse(int(product_id))
categ = self.env['product.category'].browse(int(categ_id))
pricelist = self.env['product.pricelist'].browse(int(pricelist_id))
order_lines = self.env['pos.order.line'].search([('product_id', '=', int(product_id))])
if not order_lines:
print(f"No order lines found for product {product_id}")
return False

order = order_lines[0].order_id

if not order:
print("Error: No order found for the provided product.")
return False

active_memberships = self.customer_membership_ids.filtered(lambda mem : mem.status=='active')
active_membership = False

pos_order_return = self.env.context.get('pos_order_return', False)
payment_created = self.env.context.get('payment_created', False)
discount = self.env.context.get('discount', False)
print(discount)

print(f"Context: {self.env.context}")
print(f"Received pos_order_return: {pos_order_return}, payment_created: {payment_created}")

print(f"Received appointment_id: {appointment_id}")


appointment=None
if appointment_id:
appointment = self.env['business.appointment'].browse(appointment_id)

if appointment:
membership= appointment.membership_id
print("mem",membership)
free_service_products = []
free_discount_products = []
free_discount_product_categs = []
options = {}
if appointment:
active_membership= appointment.membership_id
elif active_membership and active_memberships:
active_membership = active_memberships[0]

for membership in active_memberships:
free_discount_lines = membership.consumed_discount_ids.filtered(
lambda discount: (discount.times and discount.remaining_times) or (
not discount.times and not discount.remaining_times)
)
if free_discount_lines:
active_membership = membership
break


if appointment:
print("i got an appiotment")
active_membership= appointment.membership_id

elif active_membership and active_memberships:
print("no appiotment")
for membership in active_memberships:
valid_discount = membership.consumed_discount_ids.filtered(lambda discount: discount.remaining_times > 0)
if valid_discount:
active_membership = membership
break
else:
active_membership = active_memberships[0]


if active_membership:


free_service_lines = active_membership.consumed_service_ids.filtered(lambda service : (service.times and service.remaining_times) or (not service.times and not service.remaining_times))
free_service_products = free_service_lines.mapped('product_id')
free_discount_lines = active_membership.consumed_discount_ids.filtered(lambda discount : (discount.times and discount.remaining_times) or (not discount.times and not discount.remaining_times))
free_discount_products = free_discount_lines.mapped('product_id')
free_discount_product_categs = free_discount_lines.mapped('product_categ_id')
options['customer_membership_id'] = {'id': active_membership.id, 'name':active_membership.name, 'package_name':active_membership.membership_package_id.name}

for discount_line in free_discount_lines:
discount_line.remaining_times


if product in free_service_products:
options['price'] = 0
options['lst_price'] = 0
ser_prod_line = free_service_lines.filtered(lambda ser:ser.product_id == product)
options['consumed_service_id'] = ser_prod_line[0].id


elif product in free_discount_products:
dis_prod_line = free_discount_lines.filtered(lambda dis:dis.product_id == product)
options['discount'] = dis_prod_line[0].discount
options['consumed_discount_id'] = dis_prod_line[0].id
for order_line in order_lines:
print("discount",options['discount'])
print(
f"Discount found on product {product_id} in order {order.id}. Discount: {order_line.discount}%")

# dis_prod_line[0].consumed_times += 1
# dis_prod_line[0]._get_remaining()
if self.env.context.get('pos_order_state', 'draft') == 'draft':
if dis_prod_line[0].remaining_times > 0:
print("producuuuuuuuuuuuuuuuuuuuuuuuuct")
# dis_prod_line[0].consumed_times += 1
# dis_prod_line[0]._get_remaining()
update_applied = True

elif categ in free_discount_product_categs:
dis_categ_line = free_discount_lines.filtered(lambda dis:dis.product_categ_id == categ)
options['discount'] = dis_categ_line[0].discount
options['consumed_discount_id'] = dis_categ_line[0].id



else:
options['discount'] = 0
options['price'] = pricelist.sudo()._get_product_price(product, int(line_qty))
options['lst_price'] = pricelist.sudo()._get_product_price(product, int(line_qty))
options['customer_membership_id'] = False
options['consumed_service_id'] = False
options['consumed_discount_id'] = False
0
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Displaying Many2one field on mobile devices identical to desktop view in Odoo 17
Odoo17
Avatar
Avatar
1
čvc 25
1554
New employee Button in POS
Odoo17
Avatar
0
říj 24
2472
ADD new group under other
Odoo17
Avatar
Avatar
1
říj 24
3061
Odoo 17 kanban second Progress bar
Odoo17
Avatar
0
říj 24
2002
Time sheets - Non DB User Employees
Odoo17
Avatar
0
říj 24
1675
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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