Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

I need to add inverse function for a margin field,

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
decimalcomputeinversedecimal-accuracyDecimal-precision
1530 Vizualizări
Imagine profil
Jenish M

In purchase.order.line i have added some fields and their respective inverse method to change the corresponding fields 

class PurchaseOrderInherit(models.Model):
_inherit = "purchase.order.line"

mrp = fields.Float("MRP")
​margin = fields.Float("Mark Down%", compute="_compute_margin", inverse="_inverse_margin", digits='Product Price', store=True,
help="(MRP Excl. - Cost Excl.) / MRP Excl.")
margin_up = fields.Float("Mark Up %", compute="_compute_margin", inverse="_inverse_margin_up", digits='Product Price', store=True,
help="(MRP Excl. - Cost Excl.) / Cost Excl.")
margin_status = fields.Char("Change in Margin%", compute="_compute_margin_status", store=True)
margin_prev = fields.Float("Margin Prev %", store=True)
disc_amount = fields.Float("Disc. Amount", compute="_compute_disc_amount", inverse="_inverse_disc_amount",
help="Discount Amount for Total Quantity", store="True", digits='Product Price')

@api.depends("mrp", "product_qty", "price_subtotal", "product_id")
def _compute_margin(self):
for rec in self:
if rec.mrp and rec.price_subtotal:
base_amount = self._get_tax_amount(rec.product_id, rec.mrp) * rec.product_qty
rec.margin = (base_amount - rec.price_subtotal) / base_amount * 100 if base_amount else 0
rec.margin_up = (base_amount - rec.price_subtotal) / rec.price_subtotal * 100 if rec.price_subtotal else 0
else:
rec.margin = False
rec.margin_up = False

@api.onchange('margin_up')
def _inverse_margin_up(self):
for rec in self:
if rec.product_id and rec.margin_up not in (False, 0):
if rec.price_subtotal:
base_amount = rec.price_subtotal * (1 + rec.margin_up / 100)
rec.mrp = round(rec.product_qty and self._get_mrp_from_base_amount(rec.product_id, base_amount) / rec.product_qty)

@api.onchange('margin')
def _inverse_margin(self):
for rec in self:
base_amount = self._get_tax_amount(rec.product_id, rec.mrp)
if base_amount != 0 and rec.discount != 100:
rec.price_unit = (base_amount * (1 - rec.margin / 100)) / (1 - rec.discount / 100)

def _get_mrp_from_base_amount(self, product, base_amount):
taxes = product.taxes_id.filtered(
lambda x: x.company_id.id == self.env.company.id
or x.company_id.id == self.env.company.parent_id.id
)
tax_amount = sum(taxes.mapped('amount'))
mrp = base_amount * (1 + tax_amount / 100)
return mrp

def _get_tax_amount(self, product, price):
taxes_id = product.taxes_id.filtered(
lambda x: x.company_id.id == self.env.company.id
or x.company_id.id == self.env.company.parent_id.id
)
if taxes_id:
amount = taxes_id.compute_all(
price, product=product, partner=self.env["res.partner"]
)
amount = amount["total_excluded"]
else:
amount = price
return amount

# update margin status
@api.depends("mrp", "price_unit")
def _compute_margin_status(self):
for rec in self:
margin_prev = False
if rec.product_id.id:
margin_prev = (
self.env["purchase.order.line"]
.search(
[
("product_id", "=", rec.product_id.id),
("partner_id", "=", rec.partner_id.id),
("order_id", "!=", rec.order_id._origin.id),
("company_id", '=', self.env.company.id),
],
order="create_date desc",
limit=1,
)
.margin
)
rec.margin_prev = margin_prev
if margin_prev == False:
rec.margin_status = "NA"
elif rec.margin > margin_prev:
rec.margin_status = str(round(rec.margin - margin_prev, 1)) + " ⇑"
elif rec.margin == margin_prev:
rec.margin_status = str(round(rec.margin - margin_prev, 1)) + " ⇔"
elif rec.margin rec.margin_status = str(round(rec.margin - margin_prev, 1)) + " ⇓"

@api.depends('discount')
def _compute_disc_amount(self):
for rec in self:
if rec.discount:
rec.disc_amount = rec.price_unit * rec.product_qty * (rec.discount / 100)
else:
rec.disc_amount = 0.0

@api.onchange('disc_amount')
def _inverse_disc_amount(self):
for rec in self:
if rec.price_unit and rec.product_qty:
rec.discount = (rec.disc_amount / (rec.price_unit * rec.product_qty)) * 100

I have added all the inverse function as api.onchange() but it triggers whenever the field updates it results some unwanted values is there anything i can do
if anyone knows help me

0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
The decimal precision in the sum tree view does not follow the decimal precision in the field
decimal-accuracy Decimal-precision odoo16features
Imagine profil
0
dec. 23
1526
Inverse function on compute field Rezolvat
compute inverse odoo10
Imagine profil
Imagine profil
1
nov. 24
41407
Inverse function for making the compute field editable Rezolvat
editable compute inverse odoo12
Imagine profil
Imagine profil
Imagine profil
Imagine profil
3
aug. 24
15074
Removing decimal amount from listed price on website
decimal pricing website_builder decimal-accuracy
Imagine profil
Imagine profil
1
mai 24
2462
The translation does not change when I change the nameUA field in the view
fields translations compute inverse
Imagine profil
Imagine profil
Imagine profil
2
feb. 24
4537
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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