Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

odoo 13 : write() function updates on wrong record

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
salescouponOdoo13.0
1 Svar
2999 Visninger
Avatar
Deepak raj Inbaraj

I am new to odoo and I am working on the invoice reward splitting based on seller id.
When I split the reward discount in the sale order line the write() function updates on the wrong record may be due to tax id because the default functionality was splitting the reward discount in the sale order line with only tax.
Could anyone help me out to figure out the solution?

0
Avatar
Kassér
Apiuser

Could you post the script of what you are actually doing?

Deepak raj Inbaraj
Forfatter

I actually inherited the sales order with function _get_reward_values_discount to split discount reward line based on the product seller

def _get_reward_values_discount(self,program):
if program.discount_type == 'fixed_amount':
taxes = program.discount_line_product_id.taxes_id
if self.fiscal_position_id:
taxes = self.fiscal_position_id.map_tax(taxes)
return [{
'name': _("Discount: ") + program.name,
'product_id': program.discount_line_product_id.id,
'price_unit': - self._get_reward_values_discount_fixed_amount(program),
'product_uom_qty': 1.0,
'product_uom': program.discount_line_product_id.uom_id.id,
'is_reward_line': True,
'tax_id': [(4, tax.id, False) for tax in taxes],
}]
reward_dict = {}
lines = self._get_paid_order_lines()
amount_total = sum(self._get_base_order_lines(program).mapped('price_subtotal'))
if program.discount_apply_on == 'cheapest_product':
line = self._get_cheapest_line()
if line:
discount_line_amount = min(line.price_reduce * (program.discount_percentage / 100), amount_total)
if discount_line_amount:
taxes = line.tax_id
if self.fiscal_position_id:
taxes = self.fiscal_position_id.map_tax(taxes)

reward_dict[line.tax_id] = {
'name': _("Discount: ") + program.name,
'product_id': program.discount_line_product_id.id,
'price_unit': - discount_line_amount if discount_line_amount > 0 else 0,
'product_uom_qty': 1.0,
'product_uom': program.discount_line_product_id.uom_id.id,
'is_reward_line': True,
'tax_id': [(4, tax.id, False) for tax in taxes],
}
elif program.discount_apply_on in ['specific_products', 'on_order']:
if program.discount_apply_on == 'specific_products':
# We should not exclude reward line that offer this product since we need to offer only the discount on the real paid product (regular product - free product)
free_product_lines = self.env['sale.coupon.program'].search([('reward_type', '=', 'product'), ('reward_product_id', 'in', program.discount_specific_product_ids.ids)]).mapped('discount_line_product_id')
lines = lines.filtered(lambda x: x.product_id in (program.discount_specific_product_ids | free_product_lines))

# when processing lines we should not discount more than the order remaining total
currently_discounted_amount = 0
# _logger.info("**************************************************************************************************************************")
for line in lines:
discount_line_amount = min(self._get_reward_values_discount_percentage_per_line(program, line), amount_total - currently_discounted_amount)
# _logger.info(line.name)
# _logger.info(discount_line_amount)

if discount_line_amount:

_select_seller_id= line.product_id._select_seller().name.id +"-"+ str(line.tax_id.id)

if _select_seller_id in reward_dict:
reward_dict[_select_seller_id]['price_unit'] -= discount_line_amount
else:
taxes = line.tax_id
if self.fiscal_position_id:
taxes = self.fiscal_position_id.map_tax(taxes)

tax_name = ""
if len(taxes) == 1:
tax_name = " - " + _("On product with following tax: ") + ', '.join(taxes.mapped('name'))
elif len(taxes) > 1:
tax_name = " - " + _("On product with following taxes: ") + ', '.join(taxes.mapped('name'))

reward_dict[_select_seller_id] = {
'name': _("Discount: ") + program.name + tax_name + line.product_id._select_seller().name.name + str(discount_line_amount if discount_line_amount > 0 else 0),
'product_id': program.discount_line_product_id.id,
'price_unit': - discount_line_amount if discount_line_amount > 0 else 0,
'product_uom_qty': 1.0,
'product_uom': program.discount_line_product_id.uom_id.id,
'is_reward_line': True,
'tax_id': [(4, tax.id, False) for tax in taxes],
'partner_vendor_id' : line.product_id._select_seller().name.id,
}
currently_discounted_amount += discount_line_amount
_logger.info(reward_dict)

# _logger.info("**************************************************************************************************************************")
# If there is a max amount for discount, we might have to limit some discount lines or completely remove some lines
max_amount = program._compute_program_amount('discount_max_amount', self.currency_id)
if max_amount > 0:
amount_already_given = 0
for val in list(reward_dict):
amount_to_discount = amount_already_given + reward_dict[val]["price_unit"]
if abs(amount_to_discount) > max_amount:
reward_dict[val]["price_unit"] = - (max_amount - abs(amount_already_given))
add_name = formatLang(self.env, max_amount, currency_obj=self.currency_id)
reward_dict[val]["name"] += "( " + _("limited to ") + add_name + ")"
amount_already_given += reward_dict[val]["price_unit"]
if reward_dict[val]["price_unit"] == 0:
del reward_dict[val]
# _logger.info(reward_dict.values())
return reward_dict.values()

Avatar
Apiuser
Bedste svar

write() function works like

models.execute_kw(db, uid, password, 'model', 'write', [[id], {kwargs}])

Aren't you trying to insert a dictionary in the [id]?

0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Odoo automaticly replaces customer on sale order without reason Løst
sales ecommerce Odoo13.0
Avatar
Avatar
Avatar
Avatar
3
jan. 24
3444
How to split discount reward line based on seller id
sale.order.line coupon Odoo13.0
Avatar
0
nov. 21
2783
Sale order - delivered quantities do not match with validated deliveries
sales warehouses Odoo13.0
Avatar
0
sep. 21
2934
Why does the Invoice for a Sales Order using a Coupon not match the total? v14
sales promotion coupon
Avatar
0
nov. 20
3875
How to take a value from a popover and update Unit Price in sale.order.line?
sales widget Odoo13.0
Avatar
2
aug. 20
4177
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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