import openerp.addons.decimal_precision as dp
from openerp import workflow
+class res_company(osv.Model):
+ _inherit = "res.company"
+ _columns = {
+ 'sale_note': fields.text('Default Terms and Conditions', translate=True, help="Default terms and conditions for quotations."),
+ }
+
class sale_order(osv.osv):
_name = "sale.order"
_inherit = ['mail.thread', 'ir.needaction_mixin']
},
}
- # Hook for website_sale to inherit (website_sale_delivery)
- def _get_website_data(self, cr, uid, order, context):
- return {}
-
def copy(self, cr, uid, id, default=None, context=None):
if not default:
default = {}
val += c.get('amount', 0.0)
return val
+ def _amount_all_wrapper(self, cr, uid, ids, field_name, arg, context=None):
+ """ Wrapper because of direct method passing as parameter for function fields """
+ return self._amount_all(cr, uid, ids, field_name, arg, context=context)
+
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
cur_obj = self.pool.get('res.currency')
res = {}
sale_clause = ''
no_invoiced = False
for arg in args:
- if arg[1] == '=':
- if arg[2]:
- clause += 'AND inv.state = \'paid\''
- else:
- clause += 'AND inv.state != \'cancel\' AND sale.state != \'cancel\' AND inv.state <> \'paid\' AND rel.order_id = sale.id '
- sale_clause = ', sale_order AS sale '
- no_invoiced = True
+ if (arg[1] == '=' and arg[2]) or (arg[1] == '!=' and not arg[2]):
+ clause += 'AND inv.state = \'paid\''
+ else:
+ clause += 'AND inv.state != \'cancel\' AND sale.state != \'cancel\' AND inv.state <> \'paid\' AND rel.order_id = sale.id '
+ sale_clause = ', sale_order AS sale '
+ no_invoiced = True
cursor.execute('SELECT rel.order_id ' \
'FROM sale_order_invoice_rel AS rel, account_invoice AS inv '+ sale_clause + \
fnct_search=_invoiced_search, type='boolean', help="It indicates that sales order has at least one invoice."),
'note': fields.text('Terms and conditions'),
- 'amount_untaxed': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Untaxed Amount',
+ 'amount_untaxed': fields.function(_amount_all_wrapper, digits_compute=dp.get_precision('Account'), string='Untaxed Amount',
store={
'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
},
multi='sums', help="The amount without tax.", track_visibility='always'),
- 'amount_tax': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Taxes',
+ 'amount_tax': fields.function(_amount_all_wrapper, digits_compute=dp.get_precision('Account'), string='Taxes',
store={
'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
},
multi='sums', help="The tax amount."),
- 'amount_total': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Total',
+ 'amount_total': fields.function(_amount_all_wrapper, digits_compute=dp.get_precision('Account'), string='Total',
store={
'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
_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):
return osv.osv.unlink(self, cr, uid, unlink_ids, context=context)
def copy_quotation(self, cr, uid, ids, context=None):
- id = self.copy(cr, uid, ids[0], context=None)
+ id = self.copy(cr, uid, ids[0], context=context)
view_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'sale', 'view_order_form')
view_id = view_ref and view_ref[1] or False,
return {
context = {}
if vals.get('name', '/') == '/':
vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'sale.order') or '/'
+ if vals.get('partner_id') and any(f not in vals for f in ['partner_invoice_id', 'partner_shipping_id', 'pricelist_id']):
+ defaults = self.onchange_partner_id(cr, uid, [], vals['partner_id'], context)['value']
+ vals = dict(defaults, **vals)
context.update({'mail_create_nolog': True})
new_id = super(sale_order, self).create(cr, uid, vals, context=context)
self.message_post(cr, uid, [new_id], body=_("Quotation created"), context=context)
lines.append(line.id)
created_lines = obj_sale_order_line.invoice_line_create(cr, uid, lines)
if created_lines:
- invoices.setdefault(o.partner_id.id, []).append((o, created_lines))
+ invoices.setdefault(o.partner_invoice_id.id or o.partner_id.id, []).append((o, created_lines))
if not invoices:
for o in self.browse(cr, uid, ids, context=context):
for i in o.invoice_ids:
if grouped:
res = self._make_invoice(cr, uid, val[0][0], reduce(lambda x, y: x + y, [l for o, l in val], []), context=context)
invoice_ref = ''
+ origin_ref = ''
for o, l in val:
- invoice_ref += o.name + '|'
+ invoice_ref += (o.client_order_ref or o.name) + '|'
+ origin_ref += (o.origin or o.name) + '|'
self.write(cr, uid, [o.id], {'state': 'progress'})
cr.execute('insert into sale_order_invoice_rel (order_id,invoice_id) values (%s,%s)', (o.id, res))
#remove last '|' in invoice_ref
- if len(invoice_ref) >= 1:
+ if len(invoice_ref) >= 1:
invoice_ref = invoice_ref[:-1]
- invoice.write(cr, uid, [res], {'origin': invoice_ref, 'name': invoice_ref})
+ if len(origin_ref) >= 1:
+ origin_ref = origin_ref[:-1]
+ invoice.write(cr, uid, [res], {'origin': origin_ref, 'name': invoice_ref})
else:
for order, il in val:
res = self._make_invoice(cr, uid, order, il, context=context)
def action_button_confirm(self, cr, uid, ids, context=None):
assert len(ids) == 1, 'This option should only be used for a single id at a time.'
self.signal_order_confirm(cr, uid, ids)
-
- # redisplay the record as a sales order
- view_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'sale', 'view_order_form')
- view_id = view_ref and view_ref[1] or False,
- return {
- 'type': 'ir.actions.act_window',
- 'name': _('Sales Order'),
- 'res_model': 'sale.order',
- 'res_id': ids[0],
- 'view_type': 'form',
- 'view_mode': 'form',
- 'view_id': view_id,
- 'target': 'current',
- 'nodestroy': True,
- }
-
+ return True
+
def action_wait(self, cr, uid, ids, context=None):
context = context or {}
for o in self.browse(cr, uid, ids):
pass
return {'value': value}
+ def create(self, cr, uid, values, context=None):
+ if values.get('order_id') and values.get('product_id') and any(f not in values for f in ['name', 'price_unit', 'type', 'product_uom_qty', 'product_uom']):
+ order = self.pool['sale.order'].read(cr, uid, values['order_id'], ['pricelist_id', 'partner_id', 'date_order', 'fiscal_position'], context=context)
+ defaults = self.product_id_change(cr, uid, [], order['pricelist_id'][0], values['product_id'],
+ qty=float(values.get('product_uom_qty', False)),
+ uom=values.get('product_uom', False),
+ qty_uos=float(values.get('product_uos_qty', False)),
+ uos=values.get('product_uos', False),
+ name=values.get('name', False),
+ partner_id=order['partner_id'][0],
+ date_order=order['date_order'],
+ fiscal_position=order['fiscal_position'][0] if order['fiscal_position'] else False,
+ flag=False, # Force name update
+ context=context
+ )['value']
+ if defaults.get('tax_id'):
+ defaults['tax_id'] = [[6, 0, defaults['tax_id']]]
+ values = dict(defaults, **values)
+ return super(sale_order_line, self).create(cr, uid, values, context=context)
+
def copy_data(self, cr, uid, id, default=None, context=None):
if not default:
default = {}
raise osv.except_osv(_('Invalid Action!'), _('Cannot delete a sales order line which is in state \'%s\'.') %(rec.state,))
return super(sale_order_line, self).unlink(cr, uid, ids, context=context)
-class res_company(osv.Model):
- _inherit = "res.company"
- _columns = {
- 'sale_note': fields.text('Default Terms and Conditions', translate=True, help="Default terms and conditions for quotations."),
- }
-
class mail_compose_message(osv.Model):
_inherit = 'mail.compose.message'
def send_mail(self, cr, uid, ids, context=None):
context = context or {}
- if context.get('active_model') == 'sale.order' and context.get('active_ids') and context.get('mark_so_as_sent'):
+ if context.get('default_model') == 'sale.order' and context.get('default_res_id') and context.get('mark_so_as_sent'):
context = dict(context, mail_post_autofollow=True)
- self.pool.get('sale.order').signal_quotation_sent(cr, uid, context['active_ids'])
+ self.pool.get('sale.order').signal_quotation_sent(cr, uid, [context['default_res_id']])
return super(mail_compose_message, self).send_mail(cr, uid, ids, context=context)
sale_order_obj = self.pool.get('sale.order')
res = super(account_invoice, self).confirm_paid(cr, uid, ids, context=context)
so_ids = sale_order_obj.search(cr, uid, [('invoice_ids', 'in', ids)], context=context)
- if so_ids:
- sale_order_obj.message_post(cr, uid, so_ids, body=_("Invoice paid"), context=context)
+ for so_id in so_ids:
+ sale_order_obj.message_post(cr, uid, so_id, body=_("Invoice paid"), context=context)
return res
def unlink(self, cr, uid, ids, context=None):