Skip to Content
Menu
This question has been flagged
1 Reply
4458 Views

Dear Sir,

I completed my calculation. Now i want to show every time calculated data store in database and how i fetch data from database and show my field updated value. kindly help me. ex. first form submit value total=200

next another user submit form and this value is 300, now updated value is total 500

how i fetch data and updated value will show


.py file

from re import search

from odoo import api, models, fields


class CashinBalance(models.Model):
_name = 'cashin.balance'
_description = 'Cash-in Balance'

atk = fields.Integer('TK.1000')
btk = fields.Integer('TK.500')
ctk = fields.Integer('TK.100')
dtk = fields.Integer('TK.50')
etk = fields.Integer('TK.20')
ftk = fields.Integer('TK.10')
gtk = fields.Integer('TK.5')
htk = fields.Integer('TK.2')
date = fields.Date(required=True, default=fields.Date.context_today)
total = fields.Integer('Total Cash-In Balance' , compute='_compute_amount', store=True)
# quantity1k = fields.Integer()

@api.depends('atk', 'btk', 'ctk', 'dtk', 'etk', 'ftk', 'gtk', 'htk')
def _compute_amount(self):
for expense in self:
expense.total = expense.atk * 1000 + expense.btk*500 + expense.ctk*100 + expense.dtk*50 \
+ expense.etk*20 + expense.ftk*10 + expense.gtk*5 + expense.htk*2




.xml file

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- Tree view -->
<record id="cashin_tree_view" model="ir.ui.view">
<field name="name">cashin.tree.view</field>
<field name="model">cashin.balance</field>
<!-- <field name="view_type">form</field>-->
<!-- <field name="view_mode">tree</field>-->
<field name="arch" type="xml">
<tree string="Cash">
<field name="atk"/>
<field name="btk"/>
<field name="ctk"/>
<field name="dtk"/>
<field name="etk"/>
<field name="ftk"/>
<field name="gtk"/>
<field name="htk"/>
<field name="date"/>
<field name="total"/>
</tree>
</field>
</record>
<!-- End Tree View -->

<!-- Form View for -->
<record id="cashin_form_view" model="ir.ui.view">
<field name="name">cashin.form.view</field>
<field name="model">cashin.balance</field>
<!-- <field name="view_type">form</field>-->
<!-- <field name="view_mode">form</field>-->
<field name="arch" type="xml">
<form>
<sheet>
<group style="text-align:center" string="Yuko Leather Goods Ltd.">
</group>
<group style="text-align:center" string="Cash-In Details">
</group>

<group>
<group string="Tk-Quantity">
</group>
</group>

<group>
<group>
<field name="atk"/>
<br/>
<field name="btk"/>
<br/>
<field name="ctk"/>
<br/>
<field name="dtk"/>
<br/>
<field name="etk"/>
<br/>
<field name="ftk"/>
<br/>
<field name="gtk"/>
<br/>
<field name="htk"/>
<br/>
<field name="date"/>
<br/>
</group>
<group>
<field name="total"/>
</group>
</group>
</sheet>
</form>
</field>
</record>


<record id="action_cashin" model="ir.actions.act_window" >
<field name="name"> Cash </field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">cashin.balance</field>
<!-- <field name="view_type">form</field>-->
<field name="view_mode">tree,form</field>
</record>

<menuitem id="Cash_root" name="Cash Management" sequence="1" />
<menuitem id="cash_in" name="Cash-In" parent="Cash_root" action="action_cashin"/>
</odoo>

Avatar
Discard
Best Answer

Hello Arjun,

For that you need to create new field and store previous value into it and fetch value from it.

You can refer below code 

new field:

prev_total = fields.Integer('Previous total')


You can store previous value by adding below code:

def write(self, vals):

        for rec in self:

            vals['prev_total'] = rec.total

        super(CashinBalance, self).write(vals)


Compute total:

@api.depends('atk', 'btk', 'ctk', 'dtk', 'etk', 'ftk', 'gtk', 'htk')

    def _compute_amount(self):

        total = 0

        for expense in self:

            expense.total = expense.prev_total + expense_n + expense.atk + expense.btk+ expense.ctk+ expense.dtk\

                            + expense.etk + expense.ftk + expense.gtk+ expense.htk

            total += expense.total

Regards,




Email:      odoo@aktivsoftware.com  

Skype: kalpeshmaheshwari

   

Avatar
Discard