Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

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

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

Update the discount in POS order

Subscribe

Get notified when there's activity on this post

This question has been flagged
Odoo17
1905 Views
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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Displaying Many2one field on mobile devices identical to desktop view in Odoo 17
Odoo17
Avatar
Avatar
1
जुल॰ 25
1570
New employee Button in POS
Odoo17
Avatar
0
अक्तू॰ 24
2484
ADD new group under other
Odoo17
Avatar
Avatar
1
अक्तू॰ 24
3086
Odoo 17 kanban second Progress bar
Odoo17
Avatar
0
अक्तू॰ 24
2004
Time sheets - Non DB User Employees
Odoo17
Avatar
0
अक्तू॰ 24
1683
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة 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, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

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