from netforce.model import Model, fields, get_model from netforce.access import get_active_company, get_active_user class Sequence(Model): _inherit="sequence" _fields={ 'branch_id': fields.Many2One("clinic.branch","Branch"), "type": fields.Selection([ ["cust_invoice","Customer Invoice"], ["supp_invoice","Supplier Invoice"], ["cust_credit","Customer Credit Note"], ["supp_credit","Supplier Credit Note"], ["cust_debit","Customer Debit Note"], ["supp_debit","Supplier Debit Note"], ["pay_in","Incoming Payment"], ["pay_out","Outgoing Payment"], ["transfer","Transfer"], ["tax_no","Tax No"], ["wht_no","WHT No"], ["account_move","Journal Entry"], ["pick_in","Goods Receipt"], ["pick_internal","Goods Transfer"], ["pick_out","Goods Issue"], ["stock_count","Stock Count"], ["stock_lot","Lot / Serial Number"], ["stock_container","Container"], ["shipping_rates","Shipping Rates"], ["sale_quot","Sales Quotations"], ["sale_order","Sales Order"], ["ecom_sale_order","Ecommerce Sales Order"], ["purchase_order","Purchase Order"], ["purchase_request","Purchase Request"], ["pos_closure","POS Register Closure"], ["production","Production Order"], ["bom","Bill of Material"], ["service_item","Service Item"], ["job","Service Order"], ["service_contract","Service Contract"], ["employee","Employee"], ["payrun","Payrun"], ["leave_request","Leave Request"], ["expense","Expense Claim"], ["fixed_asset","Fixed Asset"], ["claim","Product Claims"], ["borrow","Product Borrowings"], ["clinic_patient","Patient"], ["clinic_staff","Staff"], ["clinic_visit","Visit"], ["clinic_hdcase","HD Case"], ["clinic_dlz","Dialyzer"], ["clinic_rdshop","RD Shop"], ["other","Other"]],"Type",required=True,search=True), } def find_sequence(self,type=None,name=None,context={}): if type and name: dom=[["type","=",type],["name","=",name]] elif type: dom=[["type","=",type]] elif name: dom=[["name","=",name]] company_id=get_active_company() comp_dom=dom+[["company_id","=",company_id]] user_id=get_active_user() user=get_model('base.user').browse(user_id) dpt=user.department_id branch=user.branch_id if dpt: branch_id=dpt.branch_id.id comp_dom=comp_dom+[["branch_id","=",branch_id]] elif branch: branch_id=branch.id comp_dom=comp_dom+[["branch_id","=",branch_id]] elif context.get('branch_id'): comp_dom=comp_dom+[["branch_id","=",context['branch_id']]] print('com_dom ', comp_dom) res=self.search(comp_dom,order="id") if res: return res[0] res=self.search(dom,order="id") if res: return res[0] return None Sequence.register()