Odoo Help

0

Does the payment view for CUSTOMER and SUPPLIER shares in one view for PAYMENT? Thanks in advance (SOLVED)

By
Alcaline
on 12/3/14, 12:55 AM 857 views

How will I going to required the OR number for Customer and required Checque number for Supplier?

 

In XML:

 <record id="account_voucher_receipt_dialog_form_view_inherit_sale" model="ir.ui.view">
            <field name="name">account.voucher.payment.form</field>
            <field name="model">account.voucher</field>
            <field name="inherit_id" ref="account_voucher.view_vendor_receipt_dialog_form" />
            <field name="priority" eval="30"/>
            <field name="arch" type="xml">
                <data>
                    <xpath expr="//field[@name='reference']" position="after">
                        <field name="pr_num" string="P.R. Number" placeholder="e.g. PR003/10"/>
                        <field name="or_num" domain="[('partner_id', '=', partner_id)]" invisible="context.get('hide_track',False)" attrs="{'required':('tracking','=',True)}" string="O.R. Number" placeholder="e.g. OR003/10"/>
                        <field name="cv_num"  string="C.V.Number" placeholder="e.g. CV003/10"/>
                        <field name="cheque_num"   domain="[('partner_id', '=', partner_id)]" invisible="context.get('hide_track',False)" attrs="{'required':('tracking','=',True)}" string="Checque Number" placeholder="e.g. Checque003/10"/>
                        <field name="tracking" invisible="1"/>
                    </xpath>
                </data>
            </field>
        </record>

 

In PY:

 

class account_voucher(osv.osv):
    _inherit = 'account.voucher'
    
    def _tracking(self, cursor, user, ids, name, arg, context=None):
        res = {}
        for tracklot in self.browse(cursor, user, ids, context=context):
            tracking = False
            if (tracklot.move_id.picking_id.type == 'in' and tracklot.product_id.track_incoming == True) or \
                (tracklot.move_id.picking_id.type == 'out' and tracklot.product_id.track_outgoing == True):
                tracking = True
            res[tracklot.id] = tracking
        return res
    
    def _hide_tracking(self, cursor, user, ids, name, arg, context=None):
        res = {}
        for wizard in self.browse(cursor, user, ids, context=context):
            res[wizard.id] = any([not(x.tracking) for x in wizard.move_ids])
        return res

    _columns ={
               'or_num': fields.char('O.R. Number', size=50),
               'cheque_num': fields.char('Cheque Number', size=50),
               'pr_num': fields.char('P.R. Number', size=50),
               'cv_num': fields.char('C.V. Number', size=50),
               'name':fields.char('Memo', size=256, readonly=True, states={'draft':[('readonly',False)]}),
               'type':fields.selection([('sale','Sale'),('purchase','Purchase'),('payment','Payment'),('receipt','Receipt'),],'Default Type'),
               'tracking': fields.function(_tracking, string='Tracking', type='boolean'),
               'hide_track':fields.function(_hide_tracking, string='Tracking', type='boolean'),

               }
   

account_voucher() 

1
Ivan
On 12/3/14, 1:24 AM

If you do it from Pay button yes, it use the same view.  See odoo/odoo/addons/account_voucher/invoice.py

Is there any way to required fields for 2 different payment for CUSTOMER and SUPPLIER

Alcaline
on 12/3/14, 1:29 AM

Yes there is. You can set the required attributes according to certain fields' value. If you look at the file that I've mentioned, you'll see that the invoice_type context will be different for Supplier Invoice (out_invoice), Customer Invoice (in_invoice), Supplier Refund (in_refund), and Customer Refund (out_refund). So you can change the required attribute based on the invoice_type context. Example can be found in addons/stock/wizard/stock_partial_picking_view.xml. Search for context.get.

Ivan
on 12/3/14, 3:01 AM

Do i need to create 2 views for this?

Alcaline
on 12/3/14, 3:37 AM

No.

Ivan
on 12/3/14, 3:49 AM
account.voucher.payment.form account.voucher <xpath expr="//field[@name='reference']" position="after">
Alcaline
on 12/3/14, 4:00 AM

Hi Sir I've Followed the instruction that you gave me but when i click the button an error occured Error: Unknown field undefined in domain ["tracking","=",true]

Alcaline
on 12/3/14, 4:03 AM

It's because the domain is not correct. Anyway, if you use context you don't need to use any domain. Let me quote from stock_partial_picking_view.xml: (cut the rest for clarity). So in your case, try to add invisible="context.get('invoice_type') in ['out_invoice']". Change ['out_invoice'] with the list of invoice types in which you want the field to be invisible. You can also try to do the reverse: invisible="context.get('invoice_type') not in ['in_invoice']". This time the list need to be those types that you want the field to be visible.

Ivan
on 12/3/14, 4:45 AM

Sorry, the XML got cut. Let me re-comment below.

Ivan
on 12/3/14, 4:46 AM

It's because the domain is not correct. Anyway, if you use context you don't need to use any domain. Let me quote from stock_partial_picking_view.xml: <field name="prodlot_id" domain="[('product_id', '=', product_id)]" invisible="context.get('hide_tracking',False)"...> (cut the rest for clarity). So in your case, try to add invisible="context.get('invoice_type') in ['out_invoice']". Change ['out_invoice'] with the list of invoice types in which you want the field to be invisible. You can also try to do the reverse: invisible="context.get('invoice_type') not in ['in_invoice']". This time the list need to be those types that you want the field to be visible.

Ivan
on 12/3/14, 4:47 AM
1

Hello Alcaline

 

You can use the 'type' field of account.voucher, which includes sale, purchase, payment, receipt. It is there on the view but is invisible. You can define attrs based on this field as per your requirement.

OR

You can bring the 'customer' and 'supplier' fields as related from partner screen in this pop-up form and based on that you can define the attrs on your fields.

Hope this helps

Can you please give me an example for attrs?

Alcaline
on 12/3/14, 2:23 AM

First you need to confirm what value of field 'type' comes up when you are doing the customer or supplier payments and then you can apply the attrs. Following is just the example for customer i think this will be the value ---- attrs="{'required':[('type','=','reciept')]}" for supplier i think following will be the value ----- attrs="{'required':[('type','=','payment')]}"

Emipro Technologies Pvt. Ltd.
on 12/3/14, 3:23 AM

do i need to display the "type" field??

Alcaline
on 12/3/14, 4:29 AM

@alcaline No you don't need to display the file 'type'. Just the appropriate attrs in appropriate field which you mentioned in your image. Just make sure that 'type' field remains on the form visible or invisible.

Emipro Technologies Pvt. Ltd.
on 12/3/14, 7:05 AM

do i need to create 2 views??

Alcaline
on 12/4/14, 1:00 AM

thanks Empiro. It works..

Alcaline
on 12/4/14, 3:14 AM

@Empiro Technologies what if i want to hide the or number in supplier? Do you know how to add invisible in the existing attrs??

Alcaline
on 12/4/14, 9:02 PM

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

Question tools

1 follower(s)

Stats

Asked: 12/3/14, 12:55 AM
Seen: 857 times
Last updated: 3/16/15, 8:10 AM