İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

How can I set it up so that the purchase_price (‘Cost’) field can also be changed in the ‘posted’ status in Model:'account.move'?

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
developmentaccounting
1 Cevapla
2211 Görünümler
Avatar
Martin Bando

How can I set it up so that the purchase_price (‘Cost’) field can also be changed in the ‘posted’ status? I use odoo 18.

1. I have added the costs, margin and margin (%) to the table in the ‘Accounting’ app:

from odoo import api, fields, models


class AccountMoveLine(models.Model):

    _inherit = "account.move.line"


    margin = fields.Float(

        "Margin", compute='_compute_margin',

        digits='Product Price', store=True, groups="base.group_user")

    margin_percent = fields.Float(

        "Margin (%)", compute='_compute_margin', store=True)

    purchase_price = fields.Float(

        string="Cost",

        digits='Product Price', store=True, readonly=False, copy=False)


    @api.depends('price_subtotal', 'quantity', 'purchase_price')

    def _compute_margin(self):

        for line in self:

            line.margin = line.price_subtotal - (line.purchase_price * line.quantity)

            line.margin_percent = line.price_subtotal and line.margin/line.price_subtotal 

2. Then I did the following:

class AccountMove(models.Model):

    _inherit ='account.move'


    invoice_line_ids = fields.One2many(  # /!\ invoice_line_ids is just a subset of line_ids.

        'account.move.line',

        'move_id',

        string='Invoice lines',

        copy=False,

        readonly=False,

        domain=[('display_type', 'in', ('product', 'line_section', 'line_note'))],

    )

<?xml version="1.0" encoding="utf-8"?>

<odoo>    

    <data>

        <record id="view_customer_move_form" model="ir.ui.view">

            <field name="name">account.move.customer.form</field>

            <field name="model">account.move</field>

            <field name="inherit_id" ref="account.view_move_form"/>

            <field name="arch" type="xml">

                <xpath expr="//field[@name='invoice_line_ids']" position="attributes">

                    <attribute name="readonly">0</attribute>

                </xpath>   

            </field>

        </record> 

    </data>

</odoo>

3. This is the field message I am currently receiving:

Invalid Operation

You cannot modify the following readonly fields on a posted move: invoice_line_ids

All other fields are read-only. How can I work around this?

0
Avatar
Vazgeç
Avatar
Christoph Farnleitner
En İyi Yanıt

You could achieve this by setting skip_readonly_check to the context.

In general, about How can I work around this? - first of all it's important to find out where/when exactly the error message is raised. The easiest way to do so is be taking the first view words of an error message and search for it in the core source (there could be line breaks and other things going on, so you may not find the complete string in one line - thus, search for a portion of the message). This would lead you to https://github.com/odoo/odoo/blob/18.0/addons/account/models/account_move.py#L3257


Now that you've figured that this message is raised in the write()-method of account.move when skip_readonly_check is not part of the context and the move's state is (or is becoming) posted and a unmodifiable field is to be changed, you can try to find the least intrusive way on modifying the behavior. 


One options is, as stated on top, to pass the context key skip_readonly_check under certain circumstances, namely, if nothing else but the purchase_price is being set. You could do this for example by evaluating the vals dictionary passed to the write() method:


class AccountMove(models.Model):
_inherit = 'account.move'

def write(self, vals):
print(f'vals: {vals}') # vals: {'invoice_line_ids': [[1, <line id>, {'purchase_price': <value>}]]}
if set(vals.keys()) == {'invoice_line_ids'}:
# The only change to the account move is a change in of oe or more invoice lines
for line_command in vals['invoice_line_ids']:
print(f'line_command: {line_command}') # line_command: [1, <line id>, {'purchase_price': <value>}]
if line_command[0] != 1 or set(line_command[2].keys()) != {'purchase_price'}:
# A field other than the Cost is changed on an account move line
break
else:
# Nothing but Costs are changed on invoice lines, thus it should be safe to
# skip the readonly check (relevant to posted moves only)
self = self.with_context(skip_readonly_check=True)
return super(AccountMove, self).write(vals)


It should be mentioned that this is not a final solution since other fields of an account move may need to be editable as well, for example the due date; while it still is editable, using above snipped unaltered will not allow you to change it along with a change in cost at the same time, because vals then would be something like

{'invoice_line_ids': [[1, <line id>, {'purchase_price': <value>}]], 'invoice_date_due': <date>}

and therefore the first if-condition would be False.

Side note: why the cost of a product needs to be tracked on the invoice is a whole different story. Sale Orders would allow this by default already.

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

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

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Restrict QWeb Report in Print Menu to Vendor Payments Only in Odoo 17
development accounting
Avatar
Avatar
1
Eki 25
549
Error in followup report
development accounting
Avatar
Avatar
1
Ağu 25
1645
Tax report Switzerland
development accounting
Avatar
0
May 25
1396
Individual Payment Reconcile Çözüldü
development accounting
Avatar
Avatar
1
Nis 25
2901
Vendor Credit Note Çözüldü
development accounting
Avatar
Avatar
1
Eyl 25
1968
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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