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

subtraction of invoice tamount_total from custom model amount field

Subscribe

Get notified when there's activity on this post

This question has been flagged
2 Replies
972 Views
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
Discard
Avatar
Deen Islam
Author 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
Discard
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
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
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