Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
5824 Vues

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
Ignorer
Meilleure réponse

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
Ignorer
Auteur

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

Auteur

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

Auteur

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

Auteur

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

Auteur

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

Auteur

Thanks dear Mohit. It is working now.

Publications associées Réponses Vues Activité
2
févr. 25
1173
0
mars 23
2962
1
juin 22
6682
2
avr. 19
2657
1
févr. 23
6449