Odoo Help

3

2
1 Answer
0
Alkivi SAS France
4/29/14, 7:55 AM

Hi there,

sorry about the delay ... Just started to work again on this. Overall, the technic seems OK, but here is my current issue.

On the wizard, I have a tree with several objects. User need to pick the correct one (a button seems appropriate) and then some action is performed, linking the source object (the one the wizard comes from) and the destination object (the user choice).

I'm thinking about creating an inherited object for the destination object with an extra method matching my exact needs. Any advice ? The more I go forward, the more I created complexity. I'd like a simple and elegant solution to that ;)

Cheers

Here is some code

The transaction view form (goal: launch wizard)

    <record model="ir.ui.view" id="view_linxo_transaction_form">
        <field name="name">linxo.transaction.form</field>
        <field name="model">linxo.transaction</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Transaction Info">
                <group colspan="4" col="2">
                    <field name="date" readonly="1"/>
                    <field name="label" readonly="1"/>
                    <field name="notes" readonly="1"/>
                    <field name="amount" readonly="1"/>
                    <field name="account_move_line_id"  attrs="{'invisible':[('account_move_line_id','=',False)]}" />
                    <field name="journal_id" readonly="1"/>
                </group>
                <button name="open_wizard"
                    string="Reconcile Wizard"
                    type="object"
                    help="Find associated movement" attrs="{'invisible':[('account_move_line_id','!=',False)]}"
                    class="oe_highlight" />
            </form>
        </field>
    </record>

Now the open_wizard method :

def open_wizard(self, cr, uid, ids, context=None):
    if context is None:
        context = {}
    if not ids:
        return False
    if not isinstance(ids, list):
        ids = [ids]

    transaction = self.browse(cr, uid, ids, context=context)[0]

    vals = { 'transaction_id': ids[0], 'date': transaction.date }
    if transaction.amount > 0:
        vals['debit'] = transaction.amount
    else:
        vals['credit'] = -transaction.amount

    wizard_id = self.pool.get('linxo.reconcile').create(cr, uid, vals=vals, context=context)
    return {
        'name': 'Reconcile Wizard',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'linxo.reconcile',
        'res_id': wizard_id,
        'type': 'ir.actions.act_window',
        'target': 'new',
        'context': context,
    }

The wizard class :

class linxo_reconcile(osv.osv_memory):
    _name='linxo.reconcile'

    def _get_candidates(self, cr, uid, ids, field_name, arg, context):
        """Will return a list of ids according to the match
        """
        result = {}

        wizard = self.browse(cr, uid, ids, context=context)[0]
        wizard_id = ids[0]

        transaction = wizard.transaction_id
        if not transaction:
            return result

        _logger.debug('Got transaction %d' % transaction.id)

        search_args = [
            #('date', '=', wizard.date),
            ('journal_id', '=', transaction.journal_id.id),
        ]

        if wizard.credit:
            search_args.append(('credit', '=', wizard.credit))
        else:
            search_args.append(('debit', '=', wizard.debit))

        _logger.debug('Search criteria for account.move.line')
        _logger.debug(search_args)

        account_ids = self.pool.get('account.move.line').search(cr, uid, search_args, context=context)
        _logger.debug('Search result for account.move.line')
        _logger.debug(account_ids)

        if account_ids:
            result[wizard_id] = account_ids
        else:
            #res[i] must be set to False and not to None because of XML:RPC
            # "cannot marshal None unless allow_none is enabled"
            result[wizard_id] = False

        return result

    _columns = {
        'date': fields.date('Date'),
        'debit': fields.float('Debit', digits_compute=dp.get_precision('Account')),
        'credit': fields.float('Credit', digits_compute=dp.get_precision('Account')),
        'transaction_id': fields.many2one('linxo.transaction', 'Original Transaction'),
        'candidates' : fields.function(_get_candidates, type='one2many', obj='account.move.line', method=True, string='Matching Transactions'),
    }

And finally, the wizard view :

    <record model="ir.ui.view" id="view_linxo_reconcile">
        <field name="name">linxo.reconcile.view</field>
        <field name="model">linxo.reconcile</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Reconciliation Wizard" version="7.0">
                <group string="Search criteria" col="4">
                    <field name="date" readonly="1" />
                    <field name="debit" readonly="1" />
                    <field name="credit" readonly="1" />
                </group>
                <separator string="Candidates" colspan="4"/>
                <field name='candidates'>
                    <tree string="Matching candidates">
                        <field name="date" readonly="1" />
                        <field name="debit" readonly="1" />
                        <field name="credit" readonly="1" />
                        <field name="state" readonly="1" />
                        <field name="partner_id" readonly="1" />
                    </tree>
                </field>
               <footer>
                   <button string="Cancel" special="cancel"/>
               </footer>
            </form>
        </field>
    </record>
Ask a Question
Writer
Keep Informed
2 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now