X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=addons%2Fsale%2Fsale.py;h=bdadc4489da94e9d371f85f6407f8b83376bde60;hb=6e3d1935172a877c7cdff9c6445082644d6632c0;hp=3655b3a81842cd7c10e04a938d3224bb3f490436;hpb=c1afba4742c73bd25b818515b27d793869b25fd2;p=odoo%2Fodoo.git diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 3655b3a..bdadc44 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -70,9 +70,11 @@ class sale_order(osv.osv): if not default: default = {} default.update({ + 'date_order': fields.date.context_today(self, cr, uid, context=context), 'state': 'draft', 'invoice_ids': [], 'date_confirm': False, + 'client_order_ref': '', 'name': self.pool.get('ir.sequence').get(cr, uid, 'sale.order'), }) return super(sale_order, self).copy(cr, uid, id, default, context=context) @@ -212,8 +214,7 @@ class sale_order(osv.osv): 'order_policy': fields.selection([ ('manual', 'On Demand'), ], 'Create Invoice', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, - help="""This field controls how invoice and delivery operations are synchronized. - - With 'Before Delivery', a draft invoice is created, and it must be paid before delivery."""), + help="""This field controls how invoice and delivery operations are synchronized."""), 'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Pricelist for current sales order."), 'currency_id': fields.related('pricelist_id', 'currency_id', type="many2one", relation="res.currency", string="Currency", readonly=True, required=True), 'project_id': fields.many2one('account.analytic.account', 'Contract / Analytic', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="The analytic account related to a sales order."), @@ -265,7 +266,7 @@ class sale_order(osv.osv): _sql_constraints = [ ('name_uniq', 'unique(name, company_id)', 'Order Reference must be unique per Company!'), ] - _order = 'name desc' + _order = 'date_order desc, id desc' # Form filling def unlink(self, cr, uid, ids, context=None): @@ -275,7 +276,7 @@ class sale_order(osv.osv): if s['state'] in ['draft', 'cancel']: unlink_ids.append(s['id']) else: - raise osv.except_osv(_('Invalid Action!'), _('In order to delete a confirmed sales order, you must cancel it before !')) + raise osv.except_osv(_('Invalid Action!'), _('In order to delete a confirmed sales order, you must cancel it before!')) return osv.osv.unlink(self, cr, uid, unlink_ids, context=context) @@ -315,10 +316,6 @@ class sale_order(osv.osv): return {'value': {'partner_invoice_id': False, 'partner_shipping_id': False, 'payment_term': False, 'fiscal_position': False}} part = self.pool.get('res.partner').browse(cr, uid, part, context=context) - #if the chosen partner is not a company and has a parent company, use the parent to choose the delivery, the - #invoicing addresses and all the fields related to the partner. - if part.parent_id and not part.is_company: - part = part.parent_id addr = self.pool.get('res.partner').address_get(cr, uid, [part.id], ['delivery', 'invoice', 'contact']) pricelist = part.property_product_pricelist and part.property_product_pricelist.id or False payment_term = part.property_payment_term and part.property_payment_term.id or False @@ -692,7 +689,7 @@ class sale_order_line(osv.osv): _description = 'Sales 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.text('Description', required=True, select=True, readonly=True, states={'draft': [('readonly', False)]}), + 'name': fields.text('Description', required=True, readonly=True, states={'draft': [('readonly', False)]}), 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of sales order lines."), '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), @@ -867,7 +864,7 @@ class sale_order_line(osv.osv): context = context or {} lang = lang or context.get('lang',False) if not partner_id: - raise osv.except_osv(_('No Customer Defined !'), _('Before choosing a product,\n select a customer in the sales form.')) + raise osv.except_osv(_('No Customer Defined!'), _('Before choosing a product,\n select a customer in the sales form.')) warning = {} product_uom_obj = self.pool.get('product.uom') partner_obj = self.pool.get('res.partner') @@ -1000,4 +997,20 @@ class mail_compose_message(osv.Model): wf_service.trg_validate(uid, 'sale.order', context['default_res_id'], 'quotation_sent', cr) return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context) + +class account_invoice(osv.Model): + _inherit = 'account.invoice' + + def unlink(self, cr, uid, ids, context=None): + """ Overwrite unlink method of account invoice to send a trigger to the sale workflow upon invoice deletion """ + invoice_ids = self.search(cr, uid, [('id', 'in', ids), ('state', 'in', ['draft', 'cancel'])], context=context) + #if we can't cancel all invoices, do nothing + if len(invoice_ids) == len(ids): + #Cancel invoice(s) first before deleting them so that if any sale order is associated with them + #it will trigger the workflow to put the sale order in an 'invoice exception' state + wf_service = netsvc.LocalService("workflow") + for id in ids: + wf_service.trg_validate(uid, 'account.invoice', id, 'invoice_cancel', cr) + return super(account_invoice, self).unlink(cr, uid, ids, context=context) + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: