~openerp-india/openerp-india/trunk-nco

« back to all changes in this revision

Viewing changes to maize_purchase/maize_purchase.py

  • Committer: Nimesh Contractor(OpenERP)
  • Date: 2013-06-19 12:38:26 UTC
  • mfrom: (585.1.24 trunk)
  • Revision ID: nco@tinyerp.com-20130619123826-qoc5slcoyvdo0tco
[MERGE] with main branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
197
197
        'advance_percentage': fields.function(_get_advance_percentage, string="(%)", digits_compute= dp.get_precision('Account'),store=True),
198
198
        'po_series_id': fields.related('order_id', 'po_series_id', type="many2one", relation="product.order.series", string="PO Sr", store=True),
199
199
        'po_payment_term_id': fields.related('order_id', 'payment_term_id', type="many2one", relation='account.payment.term', string="Payment Term", store=True),
200
 
        'po_delivery': fields.related('order_id', 'delivey', type="char", relation="purchase.order",string="Mill Delivery/Ex-Godown",store=True),
 
200
        'po_delivery': fields.related('order_id', 'delivey', type="many2one", relation="purchase.delivery",string="Mill Delivery/Ex-Godown",store=True),
201
201
        'po_indentor_id': fields.related('order_id', 'indentor_id', type="many2one", relation="res.users", string="Indentor",store=True),
202
202
        'po_excise': fields.function(_amount_line, multi="tax", string='Excise', digits_compute= dp.get_precision('Account'),store=True),
203
203
        'po_cess': fields.function(_amount_line, multi="tax",string='Cess', digits_compute= dp.get_precision('Account'),store=True),
257
257
 
258
258
purchase_dispatch()
259
259
 
 
260
class purchase_delivery(osv.Model):
 
261
    _name = 'purchase.delivery'
 
262
    _description = 'Purchase Delivery'
 
263
 
 
264
    _columns = {
 
265
        'name': fields.char('Name', size=64, required=True, translate=True),
 
266
        'code': fields.char('Code', size=32, required=True),
 
267
    }
 
268
 
 
269
    _sql_constraints = [
 
270
        ('code_uniq', 'unique (code)', 'The code of the dispatch must be unique!')
 
271
    ]
 
272
 
 
273
purchase_delivery()
 
274
 
260
275
class purchase_requisition_partner(osv.osv_memory):
261
276
    _inherit = "purchase.requisition.partner"
262
277
 
325
340
                'vat_amount': 0.0,
326
341
                'vat_total': 0.0,
327
342
            }
328
 
            val = val1 = packing_and_forwading = freight = excise_tax = vat_tax = other_tax = 0.0
 
343
            val = val1 = packing_and_forwading = freight = excise_tax = vat_tax = other_tax = service_tax= 0.0
329
344
            cur = order.pricelist_id.currency_id
330
345
            for line in order.order_line:
331
346
                val1 += line.price_subtotal
332
347
                amount_untaxed = val1
 
348
                vat_tax = 0.0
333
349
                price_discount = line.price_unit
334
350
                if line.discount != 0:
335
351
                    price_discount = (line.price_unit * (1 - (line.discount / 100)))
345
361
                val = excise_tax+val1
346
362
                res[order.id]['excise_total'] = val
347
363
                for vat in self.pool.get('account.tax').compute_all(cr, uid, order.vat_ids, val, 1, line.product_id, order.partner_id)['taxes']:
348
 
                    vat_tax = vat.get('amount', 0.0)
 
364
                    vat_tax += vat.get('amount', 0.0)
349
365
                res[order.id]['vat_amount'] = vat_tax
350
366
                val += vat_tax
 
367
                for service in self.pool.get('account.tax').compute_all(cr, uid, order.service_ids, val, 1, line.product_id, order.partner_id)['taxes']:
 
368
                    service_tax = service.get('amount', 0.0)
 
369
                val += service_tax
351
370
                res[order.id]['vat_total'] = val
352
371
            if order.packing_type == 'per_unit':
353
372
                other_charge = packing_and_forwading  - order.commission
427
446
        'package_and_forwording': fields.float('Packing & Forwarding', states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)],'done':[('readonly',True)]}),
428
447
        'insurance': fields.float('Insurance',  states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)],'done':[('readonly',True)]}),
429
448
        'commission': fields.float('Commission', states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)],'done':[('readonly',True)]}),
430
 
        'delivey': fields.char('Ex. GoDown / Mill Delivey',size=50, states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)],'done':[('readonly',True)]}),
 
449
        'delivey': fields.many2one('purchase.delivery', 'Ex. GoDown / Mill Delivey', states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)],'done':[('readonly',True)]}),
431
450
        'po_series_id': fields.many2one('product.order.series', 'Series', states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)],'done':[('readonly',True)]}),
432
451
        'amount_untaxed': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Untaxed Amount',
433
452
            store={
434
 
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
 
453
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['service_ids','other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
435
454
                'purchase.order.line': (_get_order, None, 10),
436
455
            }, multi="sums", help="The amount without tax", track_visibility='always'),
437
456
        'amount_tax': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Taxes',
438
457
            store={
439
 
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
 
458
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['service_ids','other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
440
459
                'purchase.order.line': (_get_order, None, 10),
441
460
            }, multi="sums", help="The tax amount"),
442
461
        'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Total',
443
462
            store={
444
 
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
 
463
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['service_ids','other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
445
464
                'purchase.order.line': (_get_order, None, 10),
446
465
            }, multi="sums",help="The total amount"),
447
466
        'other_charges': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Other Charges',
448
467
            store={
449
 
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
 
468
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['service_ids','other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
450
469
                'purchase.order.line': (_get_order, None, 10),
451
470
            }, multi="sums",help="Other Charges(computed as Packing & Forwarding - (Commission + Other Discount))"),
452
471
        'excise_amount': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Excise Amount',
453
472
            store={
454
 
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
 
473
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['service_ids','other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
455
474
                'purchase.order.line': (_get_order, None, 10),
456
475
            }, multi="sums",help="The total excise amount"),
457
476
        'excise_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Excise Total',
458
477
            store={
459
 
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
 
478
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['service_ids','other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
460
479
                'purchase.order.line': (_get_order, None, 10),
461
480
            }, multi="sums",help="The total after excise"),
462
481
        'vat_amount': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='VAT Amount',
463
482
            store={
464
 
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
 
483
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['service_ids','other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
465
484
                'purchase.order.line': (_get_order, None, 10),
466
485
            }, multi="sums",help="The total VAT amount"),
467
486
        'vat_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='VAT Total',
468
487
            store={
469
 
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
 
488
                'purchase.order': (lambda self, cr, uid, ids, c={}: ids, ['service_ids','other_tax_ids','excies_ids', 'vat_ids', 'insurance', 'insurance_type', 'freight_type','freight','packing_type','package_and_forwording','commission','other_discount', 'discount_percentage', 'order_line'], 10),
470
489
                'purchase.order.line': (_get_order, None, 10),
471
490
            }, multi="sums",help="The total after VAT"),
472
491
        'excies_ids': fields.many2many('account.tax', 'purchase_order_exices', 'exices_id', 'tax_id', 'Excise', states={'confirmed':[('readonly',True)], 'approved':[('readonly',True)],'done':[('readonly',True)]}),
572
591
            flag = False
573
592
            if po.payment_term_id:
574
593
                totlines = payment_term_obj.compute(cr, uid, po.payment_term_id.id, po.amount_total, po.date_order or False, context=context)
575
 
            journal_ids = self.pool.get('account.journal').search(cr, uid, [('code', '=', 'BNK2')], context=context)
 
594
            journal_ids = self.pool.get('account.journal').search(cr, uid, [('code', '=', 'TBNK')], context=context)
576
595
            journal_id = journal_ids and journal_ids[0] or False
577
596
            if not journal_id:
578
597
                raise osv.except_osv(_("Warning !"),_('You must define a journal related to an advance payment.'))
602
621
                pp.tender_done(context=context)
603
622
        return res
604
623
 
 
624
    def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, context=None):
 
625
        res = super(purchase_order, self)._prepare_order_line_move(cr, uid, order, order_line, picking_id, context=context)
 
626
        res = dict(res, indent = order_line.indent_id.id, indentor = order_line.indentor_id.id, department_id = order_line.department_id.id)
 
627
        return res
 
628
 
605
629
    def open_advance_payment(self, cr, uid, ids, context=None):
606
630
        '''
607
631
        This function returns an action that display advance payment of given purchase order ids.
676
700
                    'fiscal_position': porder.fiscal_position and porder.fiscal_position.id or False,                    
677
701
                    'package_and_forwording':porder.package_and_forwording or 0.0,
678
702
                    'commission':porder.commission or 0.0,
679
 
                    'delivey':porder.delivey or '',
 
703
                    'delivey':porder.delivey.id or '',
680
704
                    'dispatch_id':porder.dispatch_id and porder.dispatch_id.id or False,
681
705
                    'excies_ids':[(6,0, [excies.id for excies in porder.excies_ids])],
682
706
                    'vat_ids':[(6,0, [vat.id for vat in porder.vat_ids])],
776
800
                        move_line.append(stock_move.copy(cr,uid,move.id, dict['value'],context=context))
777
801
                        if move.product_id and move.product_id.ex_chapter:
778
802
                            vals.update({'excisable_item': True})
779
 
                    vals= {'inward_id': pick.id or False}
 
803
                    vals.update({'inward_id': pick.id or False})
780
804
                else:
781
805
                    for move in pick.backorder_id.move_lines:
782
806
                        dict = stock_move.onchange_amount(cr, uid, [move.id], pick.purchase_id.id, move.product_id.id,0,0,0, context)
783
807
                        dict['value'].update({'location_id': warehouse_dict.get('lot_input_id', False)[0], 'location_dest_id': warehouse_dict.get('lot_stock_id',False)[0]})
784
808
                        move_line.append(stock_move.copy(cr,uid,move.id, dict['value'],context=context))
 
809
                        for move in pick.move_lines:
 
810
                            stock_move.write(cr, uid, [move.id], {'challan_qty':0.0})
785
811
                        if move.product_id and move.product_id.ex_chapter:
786
812
                            vals.update({'excisable_item': True})
787
 
                    vals= {'inward_id': pick.backorder_id and pick.backorder_id.id or False}
 
813
                    vals.update({'inward_id': pick.backorder_id and pick.backorder_id.id or False})
788
814
                vals.update({'name': self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.receipt'),
789
815
                        'partner_id': pick.partner_id.id,
790
816
                        'stock_journal_id': pick.stock_journal_id or False,
796
822
 
797
823
                        })
798
824
            receipt_obj.create(cr, uid, vals, context=context)
 
825
        else:
 
826
            for pick in self.browse(cr, uid, ids, context=context):
 
827
                if pick.state != 'done' and pick.backorder_id:
 
828
                    for move in pick.move_lines:
 
829
                        stock_move.write(cr, uid, [move.id], {'challan_qty':0.0})
799
830
        for picking in self.browse(cr, uid, ids, context=context):
800
831
            seq_name = 'stock.picking'
801
832
            if picking.type == 'in':
937
968
                res[move.id]['indent_year'] = indent_year
938
969
        return res
939
970
    
 
971
    def _get_stock(self, cr, uid, ids, name, args, context=None):
 
972
        res = {}
 
973
        product_obj = self.pool.get('product.product')
 
974
        for move in self.browse(cr, uid, ids, context=context):
 
975
            product = product_obj.browse(cr, uid, [move.product_id.id])[0]
 
976
            res[move.id] = product and product.qty_available or 0.0
 
977
        return res 
 
978
    
940
979
    def _get_today(self,cr, uid, ids, name, args, context=None):
941
980
        res = {}
942
981
        for move in self.browse(cr, uid, ids, context=context):
943
982
            res[move.id] = time.strftime('%d/%m/%Y')
944
983
        return res
945
984
    
 
985
    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
 
986
        """
 
987
        @ Set Challan_qty String on the base of picking type
 
988
        """
 
989
        context = context or {}
 
990
        res = super(stock_move, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
 
991
        eview = etree.fromstring(res['arch'])
 
992
        node = eview.xpath("//field[@name='challan_qty']") and eview.xpath("//field[@name='challan_qty']")[0]
 
993
        if context.get('picking_type') == 'internal':
 
994
            if 'challan_qty' in res['fields'].keys():
 
995
                node.set('string', _('Issue Quantity'))
 
996
        if context.get('picking_type') == 'out' and node in eview:
 
997
            location = eview.xpath("//field[@name='location_id']") and eview.xpath("//field[@name='location_id']")[0] 
 
998
            location.set('modifiers', '{"invisible":false}')
 
999
            eview.remove(node)
 
1000
        if context.get('picking_type') == 'internal':
 
1001
            stock = eview.xpath("//field[@name='qty_available']") and eview.xpath("//field[@name='qty_available']")[0]
 
1002
            stock.set('modifiers', '{"invisible":false,"readonly":true}')
 
1003
        res['arch'] = etree.tostring(eview)
 
1004
        return res
 
1005
    
946
1006
    _columns = {
947
1007
            'type': fields.related('picking_id', 'type', type='selection', selection=[('out', 'Sending Goods'), ('in', 'Getting Goods'), ('internal', 'Internal'),('receipt', 'receipt')], string='Shipping Type',store=True),
948
1008
            'rate': fields.float('Rate', digits_compute= dp.get_precision('Account'), help="Rate for the product which is related to Purchase order"),
975
1035
            # required=False because we change product on_change in po line so it come black in some case
976
1036
            'name': fields.char('Description', select=True),
977
1037
            'challan_qty': fields.float('Challan Quantity', digits_compute=dp.get_precision('Product Unit of Measure'),states={'done': [('readonly', True)]},help="This Quntity is used for backorder and actual received quntity"),
 
1038
            'qty_available': fields.function(_get_stock, string="Stock", type="float")
978
1039
                }
979
1040
 
980
1041
    def onchange_amount(self, cr, uid, ids, purchase_id, product_id, diff, import_duty, tax_cal, context=None):
1039
1100
    def onchange_excise(self, cr, uid, ids, excise, cess, high_cess,import_duty, context=None):
1040
1101
        return {'value': {'excise': excise or 0.0, 'cenvat':excise or 0.0, 'cess': cess or 0.0, 'c_cess': cess or 0.0, 'high_cess': high_cess or 0.0, 'c_high_cess': high_cess or 0.0, 'import_duty': import_duty or 0.0, 'import_duty1': import_duty or 0.0}}
1041
1102
 
 
1103
    def onchange_product_id(self, cr, uid, ids, prod_id=False, loc_id=False,
 
1104
                            loc_dest_id=False, partner_id=False):
 
1105
        res = super(stock_move,self).onchange_product_id(cr, uid, ids, prod_id, loc_id, loc_dest_id, partner_id)
 
1106
        product = self.pool.get('product.product').browse(cr, uid, [prod_id])[0]
 
1107
        res['value'].update({'qty_available': product and product.qty_available or 0.0})
 
1108
        return res
 
1109
 
1042
1110
stock_move()
1043
1111
 
1044
1112
class ac_code(osv.Model):
1091
1159
 
1092
1160
tr_code()
1093
1161
 
1094
 
class stock_partial_picking(osv.osv_memory):
1095
 
    _name = "stock.partial.picking"
1096
 
    _inherit = "stock.partial.picking"
1097
 
    
1098
 
    def default_get(self, cr, uid, fields, context=None):
1099
 
        if context is None: context = {}
1100
 
        res = {}
1101
 
        picking_ids = context.get('active_ids', [])
1102
 
        active_model = context.get('active_model')
1103
 
 
1104
 
        if not picking_ids or len(picking_ids) != 1:
1105
 
            # Partial Picking Processing may only be done for one picking at a time
1106
 
            return res
1107
 
        assert active_model in ('stock.picking', 'stock.picking.in', 'stock.picking.out','stock.picking.receipt'), 'Bad context propagation'
1108
 
        picking_id, = picking_ids
1109
 
        if 'picking_id' in fields:
1110
 
            res.update(picking_id=picking_id)
1111
 
        if 'move_ids' in fields:
1112
 
            picking = self.pool.get('stock.picking').browse(cr, uid, picking_id, context=context)
1113
 
            moves = [self._partial_move_for(cr, uid, m) for m in picking.move_lines if m.state not in ('done','cancel')]
1114
 
            res.update(move_ids=moves)
1115
 
        if 'date' in fields:
1116
 
            res.update(date=time.strftime(DEFAULT_SERVER_DATETIME_FORMAT))
1117
 
        return res
1118
 
    
1119
 
    def _partial_move_for(self, cr, uid, move):
1120
 
        partial_move = {
1121
 
            'product_id' : move.product_id.id,
1122
 
            'quantity' : move.challan_qty if move.state == 'assigned' else 0,
1123
 
            'product_uom' : move.product_uom.id,
1124
 
            'prodlot_id' : move.prodlot_id.id,
1125
 
            'move_id' : move.id,
1126
 
            'location_id' : move.location_id.id,
1127
 
            'location_dest_id' : move.location_dest_id.id,
1128
 
        }
1129
 
        if move.picking_id.type == 'in' and move.product_id.cost_method == 'average':
1130
 
            partial_move.update(update_cost=True, **self._product_cost_for_average_update(cr, uid, move))
1131
 
        return partial_move