Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set the default begin date in OpenERP(Odoo)?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 638
    Comment on it

    In below example I have written Python script to Include the default begin date in OpenERP.  You can directly use the below sales module in your addons and run in Odoo server.


     

    1. from openerp.osv import fields, osv
    2.  
    3. from openerp.tools.translate import _
    4.  
    5. from openerp import SUPERUSER_ID
    6.  
    7. from openerp import api
    8.  
    9.  
    10.  
    11. class sup_brand(osv.osv):
    12.  
    13.     _name = "supplier.brand"
    14.  
    15.     _rec_name = "supplier_brand"
    16.  
    17.     _columns = {
    18.  
    19.                 'supplier_brand':fields.char('Supplier Brand'),
    20.  
    21.     }
    22.  
    23. sup_brand()
    24.  
    25.  
    26. class sup_refrence(osv.osv):
    27.  
    28.     _name = "supplier.refrence"
    29.  
    30.     _rec_name = "item_list"
    31.  
    32.     _columns = {
    33.  
    34.                 'item_list' : fields.char('Supplier reference'),
    35.  
    36.     }
    37.  
    38. sup_refrence()
    39.  
    40.  
    41. class colour_code(osv.osv):
    42.  
    43.     _name = "colour.code"
    44.  
    45.     _rec_name = "color_code"
    46.  
    47.     _columns = {
    48.  
    49.                 'color_code':fields.char('Color Code'),
    50.  
    51.     }
    52.  
    53. colour_code()
    54.  
    55.  
    56. class colour_name(osv.osv):
    57.  
    58.     _name = "colour.name"
    59.  
    60.     _rec_name = "color_name"
    61.  
    62.     _columns = {
    63.  
    64.                 'color_name':fields.char('Color Name'),
    65.  
    66.     }
    67.  
    68. colour_name()
    69.  
    70.  
    71. class product_template(osv.osv):
    72.  
    73. _name = "product.template"
    74.  
    75. _inherit = "product.template"
    76.  
    77. _columns = {
    78.  
    79. 'l_price': fields.float('Lower Price'),
    80.  
    81.                 'supp_ref' : fields.char('I Type'),
    82.  
    83. 'project_price' : fields.float('Project Price'),
    84.  
    85. 'distributor_pirce' : fields.float('Distributor price'),
    86.  
    87. 'squ_meter':fields.float('Square Meter', digits=(8,3)),
    88.  
    89. 'qty_warehous_onhand': fields.float('Qty Sqm in Warehouse', compute='_compute_qty_warehous_onhand', require = True),
    90.  
    91. 'qty_available_onhand': fields.float('Qty Sqm Available', compute='_compute_qty_available_onhand', require = True),
    92.  
    93. 'qty_avb':fields.related('qty_available', relation='product.product', string='Quantity on Hand'),
    94.  
    95. 'qty_avl':fields.related('virtual_available', relation='product.product', string='Quantity on Hand'),
    96.  
    97. 'opening_stock':fields.float('Opening Stock'),
    98.  
    99. 'size':fields.char('Size'),
    100.  
    101. 'unit_measure':fields.char('Unit Of Measure'),
    102.  
    103. 'item_list' : fields.many2one('supplier.refrence','Supplier reference'),
    104.  
    105. 'supplier_brand':fields.many2one('supplier.brand','Supplier Brand'),
    106.  
    107.                 'color_code':fields.many2one('colour.code','Color Code'),
    108.  
    109. 'color_name':fields.many2one('colour.name','Color Name'),
    110.  
    111. }
    112.  
    113.  
    114.  
    115. def button_dummy(self, cr, uid, ids, context=None):
    116.  
    117. return True
    118.  
    119.  
    120.  
    121. @api.depends('qty_avb','squ_meter')
    122.  
    123. def _compute_qty_warehous_onhand(self):
    124.  
    125. for record in self:
    126.  
    127. print "sssssssss", record.qty_avb
    128.  
    129. print "sssssssss", record.squ_meter
    130.  
    131. print "sssssssss", record._compute_qty_warehous_onhand
    132.  
    133. record.qty_warehous_onhand = record.qty_avb * record.squ_meter
    134.  
    135.  
    136.  
    137. @api.depends('qty_avl', 'squ_meter')
    138.  
    139. def _compute_qty_available_onhand(self):
    140.  
    141. for record in self:
    142.  
    143. record.qty_available_onhand = record.qty_avl * record.squ_meter
    144.  
    145. # print "plsssssssssssssssss", record.qty_warehous_onhand
    146.  
    147.  
    148. product_template()
    149.  
    150.  
    151.  
    152. class product_product(osv.osv):
    153.  
    154. _name = "product.product"
    155.  
    156. _inherit = "product.product"
    157.  
    158.  
    159. def name_get(self, cr, user, ids, context=None):
    160.  
    161. if context is None:
    162.  
    163. context = {}
    164.  
    165. if isinstance(ids, (int, long)):
    166.  
    167. ids = [ids]
    168.  
    169. if not len(ids):
    170.  
    171. return []
    172.  
    173.  
    174. def _name_get(d):
    175.  
    176. name = d.get('name','')
    177.  
    178. code = context.get('display_default_code', True) and d.get('default_code',False) or False
    179.  
    180. item_list = d.get('item_list', '')
    181.  
    182. print item_list , 'the following is the supplier refrence code'
    183.  
    184. # if code:
    185.  
    186. # name = '[%s] %s' % (code,name)
    187.  
    188. # return (d['id'], name)
    189.  
    190. if item_list:
    191.  
    192. name = '[%s] - [%s] %s' % (code,item_list,name)
    193.  
    194. return (d['id'], name)
    195.  
    196. partner_id = context.get('partner_id', False)
    197.  
    198. if partner_id:
    199.  
    200. partner_ids = [partner_id, self.pool['res.partner'].browse(cr, user, partner_id, context=context).commercial_partner_id.id]
    201.  
    202. else:
    203.  
    204. partner_ids = []
    205.  
    206.  
    207. # all user don't have access to seller and partner
    208.  
    209. # check access and use superuser
    210.  
    211. self.check_access_rights(cr, user, "read")
    212.  
    213. self.check_access_rule(cr, user, ids, "read", context=context)
    214.  
    215.  
    216. result = []
    217.  
    218. for product in self.browse(cr, SUPERUSER_ID, ids, context=context):
    219.  
    220. variant = ", ".join([v.name for v in product.attribute_value_ids])
    221.  
    222. name = variant and "%s (%s)" % (product.name, variant) or product.name
    223.  
    224. sellers = []
    225.  
    226. if partner_ids:
    227.  
    228. sellers = filter(lambda x: x.name.id in partner_ids, product.seller_ids)
    229.  
    230. if sellers:
    231.  
    232. for s in sellers:
    233.  
    234. seller_variant = s.product_name and (
    235.  
    236. variant and "%s (%s)" % (s.product_name, variant) or s.product_name
    237.  
    238. ) or False
    239.  
    240.  
    241. mydict = {
    242.  
    243. 'id': product.id,
    244.  
    245. 'name': seller_variant or name,
    246.  
    247. 'default_code': s.product_code or product.default_code,
    248.  
    249. 'item_list' : product.item_list,
    250.  
    251. }
    252.  
    253. result.append(_name_get(mydict))
    254.  
    255. else:
    256.  
    257. mydict = {
    258.  
    259. 'id': product.id,
    260.  
    261. 'name': name,
    262.  
    263. 'default_code': product.default_code,
    264.  
    265. 'item_list' : product.item_list,
    266.  
    267. }
    268.  
    269. result.append(_name_get(mydict))
    270.  
    271. return result
    272.  
    273.  
    274. product_product()
    275.  

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: