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

Hi, Please can you help me to correct this error

class account_voucher_populate_statement(models.TransientModel):
_name = "account.voucher.populate.statement"
_description = "Account Voucher Populate Statement"

journal_id = fields.Many2one(
'account.journal',
'Journal',
required=True
)
line_ids = fields.Many2many(
'account.payment',
'account_payment_line_rel',
'payment_id', 'line_id',
'Payment',
domain="[('journal_id', '=', journal_id), ('state', '=', 'posted'), ('bank_statement_line_ids', '=', False)]"
)

def get_statement_line_new(self, cr, uid, payment, statement, context=None):
# Override thi method to modifiy the new statement line to create
ctx = context.copy()
ctx['date'] = payment.date
amount = self.pool.get('res.currency').compute(cr, uid, payment.currency_id.id,
statement.currency.id, payment.amount, context=ctx)

sign = payment.type == 'payment' and -1.0 or 1.0
type = payment.type == 'payment' and 'supplier' or 'customer'
account_id = payment.type == 'payment' and payment.partner_id.property_account_payable.id or payment.partner_id.property_account_receivable.id
return {
'name': payment.reference or payment.number or '?',
'amount': sign * amount,
'type': type,
'partner_id': payment.partner_id.id,
'account_id': account_id,
'statement_id': statement.id,
'ref': payment.name,
'payment_id': payment.id,
'journal_entry_id': payment.move_id.id,
}

def populate_statement(self, cr, uid, ids, context=None):
statement_obj = self.env['account.bank.statement']
statement_line_obj = self.env['account.bank.statement.line']
payment_obj = self.env['account.payment']

if context is None:
context = {}
data = self.read(cr, uid, ids, [], context=context)[0]
payments_ids = data['line_ids']
if not payments_ids:
return {'type': 'ir.actions.act_window_close'}
statement = statement_obj.browse(
cr, uid, context['active_id'], context=context)
for payment in payment_obj.browse(cr, uid, payment_ids, context=context):
statement_line_obj.create(cr, uid,
self.get_statement_line_new(cr, uid, payment, statement, context=context), context=context)
payment_obj.write(
cr, uid, payment_ids, {'is_bank_voucher': True}, context=context)
return {'type': 'ir.actions.act_window_close'}

Avatar
Discard
Best Answer

looks like You are only passing two parameters and the method expects at least 4.
where is the call of this method? populate_statement()
try to give the same parameters calling time 


ok try to do some change like this

def populate_statement(self):
        cr = self._cr
        uid = self._uid
        ids = self._ids
        context = self._context

or

read directly without cr ids etc.

self.read()[0]

do the same with browse, create

you won't get an error

Avatar
Discard
Author

I am calling it in the view like this.

<button name="populate_statement" string="ADD" type="object" class="oe_highlight"/>

How can i do it?

ok, I think you won't get cr uid etc from the button click.

you can pass parameters in context also but it's not useful in your scenario

what exactly you want to do? maybe you need to find another way

Author

I want to get invoice payments directly in the bank.statement line as transaction. Another way is welcome. It is so urgent for me. Please.

ok I've updated my answer try if it is helpful

Author

Thanks. I try it and i get this error

File "C:\Program Files (x86)\Odoo 10.0\server\odoo\addons\account_bank_voucher\wizard\bank_statement_populate.py", line 60, in populate_statement

TypeError: read() takes at most 3 arguments (6 given)

oh you are using v10

read directly without cr ids etc.

self.read()[0]

do the same with browse, create

Author

I did it is working. Thanks a lot. but now i have a new error with the first function

def get_statement_line_new(self, cr, uid, payment, statement, context=None)

-------------------------------------------Error Details ----------------------------

File "C:\Program Files (x86)\Odoo 10.0\server\odoo\addons\account_bank_voucher\wizard\bank_statement_populate.py", line 31, in get_statement_line_new

File "C:\Program Files (x86)\Odoo 10.0\server\odoo\addons\base\res\res_currency.py", line 160, in compute

AttributeError: 'int' object has no attribute 'round'

don't use type, a type is a keyword in python.

remove that three variable and give direct value and try. something mess over there

and don't forget to tick right mark if the first question is helpful thanks

Author

Thanks Mohit. Your help is so great. I am not developper that why i have more difficult do fix bug.

I try what you said by doing this :

typee = payment.type == 'payment' and 'supplier' or 'customer'

but i still get the same error (AttributeError: 'int' object has no attribute 'round).

I don't know if i do exactly what so ask me. Thanks in advance.

just give direct value to the directory like this 'type': 'payment',

for all sign, type, account_id, and name. make it static first then you could do dynamic

Author

Thanks dear Mohit. It is working now.

Related Posts Replies Views Activity
1
Nov 24
53
0
Mar 23
1688
1
Jun 22
5872
2
Apr 19
1946
1
Feb 23
4734