From a20240b078ee8b78eab25d17fc0d925322998183 Mon Sep 17 00:00:00 2001 From: pso Date: Thu, 21 Oct 2010 15:00:04 +0530 Subject: [PATCH] [IMP] sale: cleaning module bzr revid: pso@tinyerp.com-20101021093004-lcfd7eiq2tptqutm --- addons/sale/report/sale_report.py | 33 ++++++----- addons/sale/sale.py | 55 +++++++------------ addons/sale/stock.py | 11 +--- addons/sale/wizard/sale_line_invoice.py | 6 +- addons/sale/wizard/sale_make_invoice.py | 4 +- .../sale/wizard/sale_make_invoice_advance.py | 14 ++--- 6 files changed, 50 insertions(+), 73 deletions(-) diff --git a/addons/sale/report/sale_report.py b/addons/sale/report/sale_report.py index 25046063391..75c37ff9416 100644 --- a/addons/sale/report/sale_report.py +++ b/addons/sale/report/sale_report.py @@ -30,26 +30,26 @@ class sale_report(osv.osv): _columns = { 'date': fields.date('Date Order', readonly=True), 'date_confirm': fields.date('Date Confirm', readonly=True), - 'shipped':fields.boolean('Shipped', readonly=True), - 'shipped_qty_1':fields.integer('Shipped Qty', readonly=True), + 'shipped': fields.boolean('Shipped', readonly=True), + 'shipped_qty_1': fields.integer('Shipped Qty', readonly=True), 'year': fields.char('Year', size=4, readonly=True), - 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), - ('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'), - ('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True), + 'month': fields.selection([('01', 'January'), ('02', 'February'), ('03', 'March'), ('04', 'April'), + ('05', 'May'), ('06', 'June'), ('07', 'July'), ('08', 'August'), ('09', 'September'), + ('10', 'October'), ('11', 'November'), ('12', 'December')], 'Month', readonly=True), 'day': fields.char('Day', size=128, readonly=True), - 'product_id':fields.many2one('product.product', 'Product', readonly=True), + 'product_id': fields.many2one('product.product', 'Product', readonly=True), 'uom_name': fields.char('Default UoM', size=128, readonly=True), - 'product_uom_qty':fields.float('# of Qty', readonly=True), + 'product_uom_qty': fields.float('# of Qty', readonly=True), - 'partner_id':fields.many2one('res.partner', 'Partner', readonly=True), - 'shop_id':fields.many2one('sale.shop', 'Shop', readonly=True), - 'company_id':fields.many2one('res.company', 'Company', readonly=True), - 'user_id':fields.many2one('res.users', 'Salesman', readonly=True), - 'price_total':fields.float('Total Price', readonly=True), - 'delay':fields.float('Commitment Delay', digits=(16,2), readonly=True), - 'price_average':fields.float('Average Price', readonly=True,group_operator="avg"), + 'partner_id': fields.many2one('res.partner', 'Partner', readonly=True), + 'shop_id': fields.many2one('sale.shop', 'Shop', readonly=True), + 'company_id': fields.many2one('res.company', 'Company', readonly=True), + 'user_id': fields.many2one('res.users', 'Salesman', readonly=True), + 'price_total': fields.float('Total Price', readonly=True), + 'delay': fields.float('Commitment Delay', digits=(16,2), readonly=True), + 'price_average': fields.float('Average Price', readonly=True,group_operator="avg"), 'categ_id': fields.many2one('product.category','Category of Product', readonly=True), - 'nbr':fields.integer('# of Lines', readonly=True), + 'nbr': fields.integer('# of Lines', readonly=True), 'state': fields.selection([ ('draft', 'Quotation'), ('waiting_date', 'Waiting Schedule'), @@ -124,5 +124,4 @@ class sale_report(osv.osv): """) sale_report() - - +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/sale/sale.py b/addons/sale/sale.py index caee07d4aff..f96ddb054f6 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -65,7 +65,7 @@ class sale_order(osv.osv): 'shipped': False, 'invoice_ids': [], 'picking_ids': [], - 'date_confirm':False, + 'date_confirm': False, 'name': self.pool.get('ir.sequence').get(cr, uid, 'sale.order'), }) return super(sale_order, self).copy(cr, uid, id, default, context=context) @@ -345,7 +345,6 @@ class sale_order(osv.osv): payment_term = part.property_payment_term and part.property_payment_term.id or False fiscal_position = part.property_account_position and part.property_account_position.id or False dedicated_salesman = part.user_id and part.user_id.id or uid - val = { 'partner_invoice_id': addr['invoice'], 'partner_order_id': addr['contact'], @@ -354,10 +353,8 @@ class sale_order(osv.osv): 'fiscal_position': fiscal_position, 'user_id': dedicated_salesman, } - if pricelist: val['pricelist_id'] = pricelist - return {'value': val} def shipping_policy_change(self, cr, uid, ids, policy, context=None): @@ -375,7 +372,7 @@ class sale_order(osv.osv): def write(self, cr, uid, ids, vals, context=None): if context is None: context = {} - if 'order_policy' in vals: + if vals.get('order_policy', False): if vals['order_policy'] == 'prepaid': vals.update({'invoice_quantity': 'order'}) elif vals['order_policy'] == 'picking': @@ -385,7 +382,7 @@ class sale_order(osv.osv): def create(self, cr, uid, vals, context=None): if context is None: context = {} - if 'order_policy' in vals: + if vals.get('order_policy', False): if vals['order_policy'] == 'prepaid': vals.update({'invoice_quantity': 'order'}) if vals['order_policy'] == 'picking': @@ -418,10 +415,7 @@ class sale_order(osv.osv): raise osv.except_osv(_('Error !'), _('There is no sale journal defined for this company: "%s" (id:%d)') % (order.company_id.name, order.company_id.id)) a = order.partner_id.property_account_receivable.id - if order.payment_term: - pay_term = order.payment_term.id - else: - pay_term = False + pay_term = order.payment_term and order.payment_term.id or False invoiced_sale_line_ids = self.pool.get('sale.order.line').search(cr, uid, [('order_id', '=', order.id), ('invoiced', '=', True)], context=context) from_line_invoice_ids = [] for invoiced_sale_line_id in self.pool.get('sale.order.line').browse(cr, uid, invoiced_sale_line_ids, context=context): @@ -450,7 +444,7 @@ class sale_order(osv.osv): 'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id, 'date_invoice': context.get('date_invoice',False), 'company_id': order.company_id.id, - 'user_id':order.user_id and order.user_id.id or False + 'user_id': order.user_id and order.user_id.id or False } inv.update(self._inv_get(cr, uid, order)) inv_id = inv_obj.create(cr, uid, inv, context=context) @@ -485,11 +479,10 @@ class sale_order(osv.osv): 'res_model': 'account.invoice', 'context': "{'type':'out_invoice'}", 'type': 'ir.actions.act_window', - 'nodestroy' :True, + 'nodestroy': True, 'target': 'current', 'res_id': inv_ids and inv_ids[0] or False, } - return result def action_invoice_create(self, cr, uid, ids, grouped=False, states=['confirmed', 'done', 'exception'], date_inv = False, context=None): @@ -539,7 +532,6 @@ class sale_order(osv.osv): if order.order_policy == 'picking': picking_obj.write(cr, uid, map(lambda x: x.id, order.picking_ids), {'invoice_state': 'invoiced'}) cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (order.id, res)) - return res def action_invoice_cancel(self, cr, uid, ids, context=None): @@ -591,7 +583,6 @@ class sale_order(osv.osv): # if order.state == 'invoice_except': self.write(cr, uid, [order.id], {'state': 'progress'}, context=context) - return True def action_cancel(self, cr, uid, ids, context=None): @@ -858,29 +849,29 @@ class sale_order_line(osv.osv): _description = 'Sale Order Line' _columns = { 'order_id': fields.many2one('sale.order', 'Order Reference', required=True, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]}), - 'name': fields.char('Description', size=256, required=True, select=True, readonly=True, states={'draft':[('readonly',False)]}), + 'name': fields.char('Description', size=256, required=True, select=True, readonly=True, states={'draft': [('readonly', False)]}), 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of sale order lines."), - 'delay': fields.float('Delivery Lead Time', required=True, help="Number of days between the order confirmation the the shipping of the products to the customer", readonly=True, states={'draft':[('readonly',False)]}), + 'delay': fields.float('Delivery Lead Time', required=True, help="Number of days between the order confirmation the the shipping of the products to the customer", readonly=True, states={'draft': [('readonly', False)]}), 'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], change_default=True), 'invoice_lines': fields.many2many('account.invoice.line', 'sale_order_line_invoice_rel', 'order_line_id', 'invoice_id', 'Invoice Lines', readonly=True), 'invoiced': fields.boolean('Invoiced', readonly=True), 'procurement_id': fields.many2one('procurement.order', 'Procurement'), - 'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Sale Price'), readonly=True, states={'draft':[('readonly',False)]}), + 'price_unit': fields.float('Unit Price', required=True, digits_compute= dp.get_precision('Sale Price'), readonly=True, states={'draft': [('readonly', False)]}), 'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal', digits_compute= dp.get_precision('Sale Price')), - 'tax_id': fields.many2many('account.tax', 'sale_order_tax', 'order_line_id', 'tax_id', 'Taxes', readonly=True, states={'draft':[('readonly',False)]}), - 'type': fields.selection([('make_to_stock', 'from stock'), ('make_to_order', 'on order')], 'Procurement Method', required=True, readonly=True, states={'draft':[('readonly',False)]}), - 'property_ids': fields.many2many('mrp.property', 'sale_order_line_property_rel', 'order_id', 'property_id', 'Properties', readonly=True, states={'draft':[('readonly',False)]}), + 'tax_id': fields.many2many('account.tax', 'sale_order_tax', 'order_line_id', 'tax_id', 'Taxes', readonly=True, states={'draft': [('readonly', False)]}), + 'type': fields.selection([('make_to_stock', 'from stock'), ('make_to_order', 'on order')], 'Procurement Method', required=True, readonly=True, states={'draft': [('readonly', False)]}), + 'property_ids': fields.many2many('mrp.property', 'sale_order_line_property_rel', 'order_id', 'property_id', 'Properties', readonly=True, states={'draft': [('readonly', False)]}), 'address_allotment_id': fields.many2one('res.partner.address', 'Allotment Partner'), - 'product_uom_qty': fields.float('Quantity (UoM)', digits=(16, 2), required=True, readonly=True, states={'draft':[('readonly',False)]}), - 'product_uom': fields.many2one('product.uom', 'Unit of Measure ', required=True, readonly=True, states={'draft':[('readonly',False)]}), - 'product_uos_qty': fields.float('Quantity (UoS)', readonly=True, states={'draft':[('readonly',False)]}), + 'product_uom_qty': fields.float('Quantity (UoM)', digits=(16, 2), required=True, readonly=True, states={'draft': [('readonly', False)]}), + 'product_uom': fields.many2one('product.uom', 'Unit of Measure ', required=True, readonly=True, states={'draft': [('readonly', False)]}), + 'product_uos_qty': fields.float('Quantity (UoS)', readonly=True, states={'draft': [('readonly', False)]}), 'product_uos': fields.many2one('product.uom', 'Product UoS'), 'product_packaging': fields.many2one('product.packaging', 'Packaging'), 'move_ids': fields.one2many('stock.move', 'sale_line_id', 'Inventory Moves', readonly=True), - 'discount': fields.float('Discount (%)', digits=(16, 2), readonly=True, states={'draft':[('readonly',False)]}), + 'discount': fields.float('Discount (%)', digits=(16, 2), readonly=True, states={'draft': [('readonly', False)]}), 'number_packages': fields.function(_number_packages, method=True, type='integer', string='Number Packages'), 'notes': fields.text('Notes'), - 'th_weight': fields.float('Weight', readonly=True, states={'draft':[('readonly',False)]}), + 'th_weight': fields.float('Weight', readonly=True, states={'draft': [('readonly', False)]}), 'state': fields.selection([('draft', 'Draft'),('confirmed', 'Confirmed'),('done', 'Done'),('cancel', 'Cancelled'),('exception', 'Exception')], 'State', required=True, readonly=True, help='* The \'Draft\' state is set when the related sale order in draft state. \ \n* The \'Confirmed\' state is set when the related sale order is confirmed. \ @@ -889,7 +880,7 @@ class sale_order_line(osv.osv): \n* The \'Cancelled\' state is set when a user cancel the sale order related.'), 'order_partner_id': fields.related('order_id', 'partner_id', type='many2one', relation='res.partner', string='Customer'), 'salesman_id':fields.related('order_id', 'user_id', type='many2one', relation='res.users', string='Salesman'), - 'company_id': fields.related('order_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True, states={'draft':[('readonly',False)]}), + 'company_id': fields.related('order_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True, states={'draft': [('readonly', False)]}), } _order = 'sequence, id desc' _defaults = { @@ -897,7 +888,7 @@ class sale_order_line(osv.osv): 'delay': 0.0, 'product_uom_qty': 1, 'product_uos_qty': 1, - 'sequence': 10, + 'sequence': 10, 'invoiced': 0, 'state': 'draft', 'type': 'make_to_stock', @@ -1049,7 +1040,6 @@ class sale_order_line(osv.osv): return {'value': {'th_weight': 0, 'product_packaging': False, 'product_uos_qty': qty}, 'domain': {'product_uom': [], 'product_uos': []}} - if not date_order: date_order = time.strftime('%Y-%m-%d') @@ -1081,7 +1071,6 @@ class sale_order_line(osv.osv): uom2 = product_uom_obj.browse(cr, uid, uom) if product_obj.uom_id.category_id.id != uom2.category_id.id: uom = False - if uos: if product_obj.uos_id: uos2 = product_uom_obj.browse(cr, uid, uos) @@ -1142,10 +1131,7 @@ class sale_order_line(osv.osv): max(0,product_obj.virtual_available), product_obj.uom_id.name, max(0,product_obj.qty_available), product_obj.uom_id.name) } - - # get unit price - if not pricelist: warning = { 'title': 'No Pricelist !', @@ -1189,12 +1175,11 @@ class sale_order_line(osv.osv): """Allows to delete sale order lines in draft,cancel states""" for rec in self.browse(cr, uid, ids, context=context): if rec.state not in ['draft', 'cancel']: - raise osv.except_osv(_('Invalid action !'), _('Cannot delete a sale order line which is %s !')%(rec.state,)) + raise osv.except_osv(_('Invalid action !'), _('Cannot delete a sale order line which is %s !') %(rec.state,)) return super(sale_order_line, self).unlink(cr, uid, ids, context=context) sale_order_line() - class sale_config_picking_policy(osv.osv_memory): _name = 'sale.config.picking_policy' _inherit = 'res.config' diff --git a/addons/sale/stock.py b/addons/sale/stock.py index ae29b70837b..f9e0c38494b 100644 --- a/addons/sale/stock.py +++ b/addons/sale/stock.py @@ -116,10 +116,8 @@ class stock_picking(osv.osv): result = super(stock_picking, self).action_invoice_create(cursor, user, ids, journal_id=journal_id, group=group, type=type, context=context) - picking_ids = result.keys() invoice_ids = result.values() - invoices = {} for invoice in invoice_obj.browse(cursor, user, invoice_ids, context=context): @@ -127,20 +125,16 @@ class stock_picking(osv.osv): for picking in picking_obj.browse(cursor, user, picking_ids, context=context): - if not picking.sale_id: continue sale_lines = picking.sale_id.order_line invoice_created = invoices[result[picking.id]] - for inv in invoice_obj.browse(cursor, user, [invoice_created.id], context=context): if not inv.fiscal_position: invoice_obj.write(cursor, user, [inv.id], {'fiscal_position': picking.sale_id.fiscal_position.id}, context=context) - if picking.sale_id.client_order_ref: inv_name = picking.sale_id.client_order_ref + " : " + invoice_created.name invoice_obj.write(cursor, user, [invoice_created.id], {'name': inv_name}, context=context) - for sale_line in sale_lines: if sale_line.product_id.type == 'service' and sale_line.invoiced == False: if group: @@ -182,10 +176,9 @@ class stock_picking(osv.osv): 'account_analytic_id': account_analytic_id, 'notes':sale_line.notes }, context=context) - self.pool.get('sale.order.line').write(cursor, user, [sale_line.id], {'invoiced':True, + self.pool.get('sale.order.line').write(cursor, user, [sale_line.id], {'invoiced': True, 'invoice_lines': [(6, 0, [invoice_line_id])], }) - return result def action_cancel(self, cr, uid, ids, context={}): @@ -194,7 +187,7 @@ class stock_picking(osv.osv): call_ship_end = True if pick.sale_id: for picks in pick.sale_id.picking_ids: - if picks.state not in ('done','cancel'): + if picks.state not in ('done', 'cancel'): call_ship_end = False break if call_ship_end: diff --git a/addons/sale/wizard/sale_line_invoice.py b/addons/sale/wizard/sale_line_invoice.py index 4281e180970..c5a6a0e9846 100644 --- a/addons/sale/wizard/sale_line_invoice.py +++ b/addons/sale/wizard/sale_line_invoice.py @@ -68,7 +68,7 @@ class sale_order_line_make_invoice(osv.osv_memory): 'partner_id': order.partner_id.id, 'address_invoice_id': order.partner_invoice_id.id, 'address_contact_id': order.partner_invoice_id.id, - 'invoice_line': [(6,0,lines)], + 'invoice_line': [(6, 0, lines)], 'currency_id' : order.pricelist_id.currency_id.id, 'comment': order.note, 'payment_term': pay_term, @@ -81,7 +81,7 @@ class sale_order_line_make_invoice(osv.osv_memory): sales_order_obj = self.pool.get('sale.order') wf_service = netsvc.LocalService('workflow') for line in sales_order_line_obj.browse(cr, uid, context['active_ids']): - if (not line.invoiced) and (line.state not in ('draft','cancel')): + if (not line.invoiced) and (line.state not in ('draft', 'cancel')): if not line.order_id.id in invoices: invoices[line.order_id.id] = [] line_id = sales_order_line_obj.invoice_line_create(cr, uid, @@ -105,7 +105,7 @@ class sale_order_line_make_invoice(osv.osv_memory): break if flag: wf_service.trg_validate(uid, 'sale.order', line.order_id.id, 'all_lines', cr) - sales_order_obj.write(cr, uid, [line.order_id.id], {'state' : 'progress'}) + sales_order_obj.write(cr, uid, [line.order_id.id], {'state': 'progress'}) if not invoices: raise osv.except_osv(_('Warning'), _('Invoice cannot be created for this Sale Order Line due to one of the following reasons:\n1.The state of this sale order line is either "draft" or "cancel"!\n2.The Sale Order Line is Invoiced!')) diff --git a/addons/sale/wizard/sale_make_invoice.py b/addons/sale/wizard/sale_make_invoice.py index 8d0b191620b..242d83c72ef 100644 --- a/addons/sale/wizard/sale_make_invoice.py +++ b/addons/sale/wizard/sale_make_invoice.py @@ -27,7 +27,7 @@ class sale_make_invoice(osv.osv_memory): _description = "Sale Make Invoice" _columns = { 'grouped': fields.boolean('Group the invoices', help='Check the box to group the invoices for the same customers'), - 'invoice_date':fields.date('Invoice Date'), + 'invoice_date': fields.date('Invoice Date'), } _defaults = { 'grouped': False @@ -66,7 +66,7 @@ class sale_make_invoice(osv.osv_memory): 'view_mode': 'tree,form', 'res_model': 'account.invoice', 'view_id': False, - 'context': "{'type':'out_refund'}", + 'context': "{'type': 'out_refund'}", 'type': 'ir.actions.act_window', 'search_view_id': id['res_id'] } diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py index ea7cdd56704..afb9edd3301 100644 --- a/addons/sale/wizard/sale_make_invoice_advance.py +++ b/addons/sale/wizard/sale_make_invoice_advance.py @@ -83,12 +83,12 @@ class sale_advance_payment_inv(osv.osv_memory): 'reference': False, 'account_id': sale.partner_id.property_account_receivable.id, 'partner_id': sale.partner_id.id, - 'address_invoice_id':sale.partner_invoice_id.id, - 'address_contact_id':sale.partner_order_id.id, + 'address_invoice_id': sale.partner_invoice_id.id, + 'address_contact_id': sale.partner_order_id.id, 'invoice_line': [(6, 0, create_ids)], - 'currency_id' :sale.pricelist_id.currency_id.id, + 'currency_id': sale.pricelist_id.currency_id.id, 'comment': '', - 'payment_term':sale.payment_term.id, + 'payment_term': sale.payment_term.id, 'fiscal_position': sale.fiscal_position.id or sale.partner_id.property_account_position.id } @@ -98,7 +98,7 @@ class sale_advance_payment_inv(osv.osv_memory): for inv in sale.invoice_ids: ids_inv.append(inv.id) ids_inv.append(inv_id) - obj_sale.write(cr, uid, sale.id, {'invoice_ids':[(6, 0, ids_inv)]}) + obj_sale.write(cr, uid, sale.id, {'invoice_ids': [(6, 0, ids_inv)]}) list_inv.append(inv_id) # # If invoice on picking: add the cost on the SO @@ -127,7 +127,7 @@ class sale_advance_payment_inv(osv.osv_memory): 'res_model': 'sale.open.invoice', 'type': 'ir.actions.act_window', 'target': 'new', - 'context':context + 'context': context } sale_advance_payment_inv() @@ -164,7 +164,7 @@ class sale_open_invoice(osv.osv_memory): 'res_id': int(context['invoice_id'][0]), 'view_id': False, 'views': [(form_res, 'form'), (tree_res, 'tree')], - 'context': "{'type':'out_invoice'}", + 'context': "{'type': 'out_invoice'}", 'type': 'ir.actions.act_window', }