diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 469acc2e317..a73b6fd35ec 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -1347,7 +1347,7 @@ class account_invoice_line(models.Model): if type in ('in_invoice', 'in_refund'): values['price_unit'] = price_unit or product.standard_price else: - values['price_unit'] = product.list_price + values['price_unit'] = product.lst_price values['uos_id'] = uom_id or product.uom_id.id domain = {'uos_id': [('category_id', '=', product.uom_id.category_id.id)]} diff --git a/addons/account_followup/tests/test_account_followup.py b/addons/account_followup/tests/test_account_followup.py index 697fb433362..2f1bc2dfb15 100644 --- a/addons/account_followup/tests/test_account_followup.py +++ b/addons/account_followup/tests/test_account_followup.py @@ -1,9 +1,8 @@ - - import datetime from openerp import tools from openerp.tests.common import TransactionCase +from openerp.osv import fields class TestAccountFollowup(TransactionCase): def setUp(self): @@ -45,14 +44,15 @@ class TestAccountFollowup(TransactionCase): self.registry('account.invoice').signal_workflow(cr, uid, [self.invoice_id], 'invoice_open') self.voucher = self.registry("account.voucher") + + self.current_date = datetime.datetime.strptime(fields.date.context_today(self.user, cr, uid, context={}), tools.DEFAULT_SERVER_DATE_FORMAT) def test_00_send_followup_after_3_days(self): """ Send follow up after 3 days and check nothing is done (as first follow-up level is only after 15 days)""" cr, uid = self.cr, self.uid - current_date = datetime.datetime.utcnow() delta = datetime.timedelta(days=3) - result = current_date + delta + result = self.current_date + delta self.wizard_id = self.wizard.create(cr, uid, {'date':result.strftime(tools.DEFAULT_SERVER_DATE_FORMAT), 'followup_id': self.followup_id }, context={"followup_id": self.followup_id}) @@ -61,33 +61,32 @@ class TestAccountFollowup(TransactionCase): def run_wizard_three_times(self): cr, uid = self.cr, self.uid - current_date = datetime.datetime.utcnow() delta = datetime.timedelta(days=40) - result = current_date + delta + result = self.current_date + delta + result = self.current_date + delta self.wizard_id = self.wizard.create(cr, uid, {'date':result.strftime(tools.DEFAULT_SERVER_DATE_FORMAT), 'followup_id': self.followup_id }, context={"followup_id": self.followup_id}) - self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id, 'tz':'UTC'}) + self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id}) self.wizard_id = self.wizard.create(cr, uid, {'date':result.strftime(tools.DEFAULT_SERVER_DATE_FORMAT), 'followup_id': self.followup_id }, context={"followup_id": self.followup_id}) - self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id, 'tz':'UTC'}) + self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id}) self.wizard_id = self.wizard.create(cr, uid, {'date':result.strftime(tools.DEFAULT_SERVER_DATE_FORMAT), 'followup_id': self.followup_id, }, context={"followup_id": self.followup_id}) - self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id, 'tz':'UTC'}) + self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id}) def test_01_send_followup_later_for_upgrade(self): """ Send one follow-up after 15 days to check it upgrades to level 1""" cr, uid = self.cr, self.uid - current_date = datetime.datetime.utcnow() delta = datetime.timedelta(days=15) - result = current_date + delta + result = self.current_date + delta self.wizard_id = self.wizard.create(cr, uid, { 'date':result.strftime(tools.DEFAULT_SERVER_DATE_FORMAT), 'followup_id': self.followup_id }, context={"followup_id": self.followup_id}) - self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id, 'tz':'UTC'}) + self.wizard.do_process(cr, uid, [self.wizard_id], context={"followup_id": self.followup_id}) self.assertEqual(self.partner.browse(cr, uid, self.partner_id).latest_followup_level_id.id, self.first_followup_line_id, "Not updated to the correct follow-up level") @@ -98,7 +97,7 @@ class TestAccountFollowup(TransactionCase): self.assertEqual(self.partner.browse(cr, uid, self.partner_id).payment_next_action, "Call the customer on the phone! ", "Manual action not set") self.assertEqual(self.partner.browse(cr, uid, self.partner_id).payment_next_action_date, - datetime.datetime.utcnow().strftime(tools.DEFAULT_SERVER_DATE_FORMAT)) + self.current_date.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)) def test_03_filter_on_credit(self): """ Check the partners can be filtered on having credits """ @@ -134,9 +133,8 @@ class TestAccountFollowup(TransactionCase): """Run wizard until manual action, pay the invoice and check that partner has no follow-up level anymore and after running the wizard the action is empty""" cr, uid = self.cr, self.uid self.test_02_check_manual_action() - current_date = datetime.datetime.utcnow() delta = datetime.timedelta(days=1) - result = current_date + delta + result = self.current_date + delta self.invoice.pay_and_reconcile(cr, uid, [self.invoice_id], 1000.0, self.pay_account_id, self.period_id, self.journal_id, self.pay_account_id, self.period_id, self.journal_id, diff --git a/addons/account_payment/account_move_line.py b/addons/account_payment/account_move_line.py index b955356d291..8bfe07573a0 100644 --- a/addons/account_payment/account_move_line.py +++ b/addons/account_payment/account_move_line.py @@ -19,13 +19,48 @@ # ############################################################################## -from openerp.osv import osv +from openerp.osv import fields, osv from openerp.tools.translate import _ from openerp.exceptions import UserError +from operator import itemgetter class account_move_line(osv.osv): _inherit = "account.move.line" + def _amount_residual(self, cr, uid, ids, field_names, args, context=None): + return self._amount_residual(self, cr, uid, ids, field_names, args, context=context) + + def _to_pay_search(self, cr, uid, obj, name, args, context=None): + if not args: + return [] + line_obj = self.pool.get('account.move.line') + query = line_obj._query_get(cr, uid, context={}) + where = ' and '.join(map(lambda x: '''(SELECT + CASE WHEN l.amount_currency < 0 + THEN - l.amount_currency + ELSE l.credit + END - coalesce(sum(pl.amount_currency), 0) + FROM payment_line pl + INNER JOIN payment_order po ON (pl.order_id = po.id) + WHERE move_line_id = l.id + AND po.state != 'cancel' + ) %(operator)s %%s ''' % {'operator': x[1]}, args)) + sql_args = tuple(map(itemgetter(2), args)) + + cr.execute(('''SELECT id + FROM account_move_line l + WHERE account_id IN (select id + FROM account_account + WHERE type=%s AND active) + AND reconcile_id IS null + AND credit > 0 + AND ''' + where + ' and ' + query), ('payable',)+sql_args ) + + res = cr.fetchall() + if not res: + return [('id', '=', '0')] + return [('id', 'in', map(lambda x:x[0], res))] + def line2bank(self, cr, uid, ids, payment_type=None, context=None): """ Try to return for each Ledger Posting line a corresponding bank @@ -57,3 +92,8 @@ class account_move_line(osv.osv): else: raise UserError(_('There is no partner defined on the entry line.')) return line2bank + + _columns = { + 'amount_to_pay': fields.function(_amount_residual, + type='float', string='Amount to pay', fnct_search=_to_pay_search), + } diff --git a/addons/account_payment/account_payment_view.xml b/addons/account_payment/account_payment_view.xml index 512d3281eee..c4088a62ee6 100644 --- a/addons/account_payment/account_payment_view.xml +++ b/addons/account_payment/account_payment_view.xml @@ -89,7 +89,7 @@ - +