Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (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
1866 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
Jul 25
1524
New employee Button in POS
Odoo17
Avatar
0
Oct 24
2393
ADD new group under other
Odoo17
Avatar
Avatar
1
Oct 24
3016
Odoo 17 kanban second Progress bar
Odoo17
Avatar
0
Oct 24
1955
Time sheets - Non DB User Employees
Odoo17
Avatar
0
Oct 24
1624
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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