This question has been flagged
2 Replies
2587 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() 

Avatar
Discard
Best Answer

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

Avatar
Discard
Author

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

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.

Author

Do i need to create 2 views for this?

No.

Author
account.voucher.payment.form account.voucher <xpath expr="//field[@name='reference']" position="after">
Author

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]

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.

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

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.

Best Answer

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

Avatar
Discard
Author

Can you please give me an example for attrs?

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')]}"

Author

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

@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.

Author

do i need to create 2 views??

Author

thanks Empiro. It works..

Author

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