Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

subtraction of invoice tamount_total from custom model amount field

Naroči se

Get notified when there's activity on this post

This question has been flagged
2 Odgovori
969 Prikazi
Avatar
Deen Islam
def action_generate_bill(self):
# Assuming you have necessary information for creating the invoice
invoice_data = {
# 'payment_reference': self.type_id.id, # Replace with the actual partner field in your model
# 'partner_id': self.user_id.id, # Replace with other necessary fields
'move_type': 'out_invoice' # if it is an invoice otherwise in_invoice if it is a bill
# Add more fields as needed
}

# Create a new invoice
new_invoice = self.env['account.move'].create(invoice_data)

# Find the corresponding baba.approve record based on type_id

approve_record = self.env['baba.approval'].search([('type_id', '=', self.type_id.id)])

# If a matching record is found, create invoice lines with adjusted amounts
if approve_record:
for line in new_invoice.invoice_line_ids:
line.price_unit -= approve_record.approve_amount

# Open the form view of the newly created invoice
action = {
'type': 'ir.actions.act_window',
'res_model': 'account.move',
'view_mode': 'form',
'res_id': new_invoice.id,
}

return action
here is my function when i clcik on this button then it take me to account.nove invoice
i have add a a many2one field in both model to tract the same
class MultiApproval(models.Model):
_name = 'baba.approval'
type_id = fields.Many2one(
string="Type", comodel_name="baba.approval.type", required=True)
class AccountAmount(models.Model):
_inherit = "account.move"
type_id = fields.Many2one(
string="Type", comodel_name="baba.approval.type", required=True)
in my baba.approval model there is a field
approve_amount = fields.Float('Approved Amount') here i define the amount now i want when type_id is same in the both model then what price i add in the account.move model amount_total filed value is subtraction from approve_amount
examle is my approve amount is 5000 and in the same type_id amount_total is 3000 then my approve_amount automatically will be 2000 when this invoice is in posted state
how i do this


0
Avatar
Opusti
Avatar
Deen Islam
Avtor Best Answer

hi james 
thanks for your support 

type_id = fields.Many2one(
string="Type", comodel_name="baba.approval.type", required=True)
approve_amount = fields.Float('Approved Amount',compute='_compute_approve_amount')

@api.depends('type_id')
def _compute_approve_amount(self):
if self.new_invoice.state == 'posted' and self.new_invoice and self.type_id == self.new_invoice.type_id:
self.approve_amount = self.approve_amount - self.new_invoice.amount_total
def action_generate_bill(self):
# Assuming you have necessary information for creating the invoice
invoice_data = {
# 'payment_reference': self.type_id.id, # Replace with the actual partner field in your model
# 'partner_id': self.user_id.id, # Replace with other necessary fields
'move_type': 'out_invoice' # if it is an invoice otherwise in_invoice if it is a bill
# Add more fields as needed
}

# Create a new invoice
new_invoice = self.env['account.move'].create(invoice_data)

# Find the corresponding baba.approve record based on type_id
approve_record = self.env['baba.approval'].search([('type_id', '=', self.type_id.id)])

# If a matching record is found, create invoice lines with adjusted amounts
if approve_record:
for line in new_invoice.invoice_line_ids:
line.price_unit -= approve_record.approve_amount

# Open the form view of the newly created invoice
action = {
'type': 'ir.actions.act_window',
'res_model': 'account.move',
'view_mode': 'form',
'res_id': new_invoice.id,
}

return action
i have try this but its not wokring
here i want from my approve_amount field of same type_Id in account.move model amount_total will be substraction when the innvoice is in posted state



0
Avatar
Opusti
Avatar
Mily Shajan
Best Answer

Hi Deen 

check the code following, 

assign created new_invoice record to a many2one of 'account.move'  in your model 

class MultiApproval(models.Model):
_name = 'baba.approval'

type_id = fields.Many2one(
string="Type", comodel_name="baba.approval.type", required=True)
approve_amount = fields.Float('Approved Amount',compute='_compute_approve_amount')

@api.depends('type_id')
def _compute_approve_amount(self):
if self.new_invoice.state == 'posted' and self.new_invoice and self.type_id == self.new_invoice.type_id:
self.approve_amount = self.approve_amount - self.new_invoice.amount_total

Regards

0
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

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

Prijavi
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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