diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index b4fc2388a68..8b2a9aff257 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -461,10 +461,9 @@ class account_bank_statement(osv.osv): return {} balance_start = self._compute_balance_end_real(cr, uid, journal_id, context=context) - journal_data = self.pool.get('account.journal').read(cr, uid, journal_id, ['default_debit_account_id', 'company_id'], context=context) - account_id = journal_data['default_debit_account_id'] + journal_data = self.pool.get('account.journal').read(cr, uid, journal_id, ['company_id'], context=context) company_id = journal_data['company_id'] - return {'value': {'balance_start': balance_start, 'account_id': account_id, 'company_id': company_id}} + return {'value': {'balance_start': balance_start, 'company_id': company_id}} def unlink(self, cr, uid, ids, context=None): stat = self.read(cr, uid, ids, ['state'], context=context) diff --git a/addons/account/test/account_supplier_invoice.yml b/addons/account/test/account_supplier_invoice.yml index 9c5ce2dea3e..02c3d367050 100644 --- a/addons/account/test/account_supplier_invoice.yml +++ b/addons/account/test/account_supplier_invoice.yml @@ -21,7 +21,7 @@ - I create a supplier invoice - - !record {model: account.invoice, id: account_invoice_supplier0}: + !record {model: account.invoice, id: account_invoice_supplier0, view: invoice_supplier_form}: account_id: account.a_pay check_total: 3000.0 company_id: base.main_company diff --git a/addons/account_payment/wizard/account_payment_populate_statement.py b/addons/account_payment/wizard/account_payment_populate_statement.py index ecfd4988329..fffe6c17b92 100644 --- a/addons/account_payment/wizard/account_payment_populate_statement.py +++ b/addons/account_payment/wizard/account_payment_populate_statement.py @@ -86,24 +86,24 @@ class account_payment_populate_statement(osv.osv_memory): 'name': line.name, 'partner_id': line.partner_id.id, 'journal_id': statement.journal_id.id, - 'account_id': result.get('account_id', statement.journal_id.default_credit_account_id.id), + 'account_id': result['value'].get('account_id', statement.journal_id.default_credit_account_id.id), 'company_id': statement.company_id.id, 'currency_id': statement.currency.id, 'date': line.date or time.strftime('%Y-%m-%d'), 'amount': abs(amount), - 'period_id': statement.period_id.id + 'period_id': statement.period_id.id, } voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context) - voucher_line_dict = False - if result['value']['line_ids']: - for line_dict in result['value']['line_ids']: - move_line = move_line_obj.browse(cr, uid, line_dict['move_line_id'], context) - if line.move_line_id.move_id.id == move_line.move_id.id: - voucher_line_dict = line_dict + + voucher_line_dict = {} + for line_dict in result['value']['line_cr_ids'] + result['value']['line_dr_ids']: + move_line = move_line_obj.browse(cr, uid, line_dict['move_line_id'], context) + if line.move_line_id.move_id.id == move_line.move_id.id: + voucher_line_dict = line_dict + if voucher_line_dict: voucher_line_dict.update({'voucher_id': voucher_id}) voucher_line_obj.create(cr, uid, voucher_line_dict, context=context) - st_line_id = statement_line_obj.create(cr, uid, { 'name': line.order_id.reference or '?', 'amount': - amount, diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 4b0365e1a11..423026251c2 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -547,6 +547,19 @@ class account_voucher(osv.osv): vals = self.recompute_payment_rate(cr, uid, ids, res, currency_id, date, ttype, journal_id, amount, context=context) for key in vals.keys(): res[key].update(vals[key]) + #TODO: onchange_partner_id() should not returns [pre_line, line_dr_ids, payment_rate...] for type sale, and not + # [pre_line, line_cr_ids, payment_rate...] for type purchase. + # We should definitively split account.voucher object in two and make distinct on_change functions. In the + # meanwhile, bellow lines must be there because the fields aren't present in the view, what crashes if the + # onchange returns a value for them + if ttype == 'sale': + del(res['value']['line_dr_ids']) + del(res['value']['pre_line']) + del(res['value']['payment_rate']) + elif ttype == 'purchase': + del(res['value']['line_cr_ids']) + del(res['value']['pre_line']) + del(res['value']['payment_rate']) return res def recompute_voucher_lines(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=None): @@ -588,7 +601,7 @@ class account_voucher(osv.osv): #set default values default = { - 'value': {'line_ids': [] ,'line_dr_ids': [] ,'line_cr_ids': [] ,'pre_line': False,}, + 'value': {'line_dr_ids': [] ,'line_cr_ids': [] ,'pre_line': False,}, } #drop existing lines @@ -667,6 +680,7 @@ class account_voucher(osv.osv): #voucher line creation for line in account_move_lines: + if _remove_noise_in_o2m(): continue @@ -771,8 +785,10 @@ class account_voucher(osv.osv): if account_id and account_id.tax_ids: tax_id = account_id.tax_ids[0].id - vals = self.onchange_price(cr, uid, ids, line_ids, tax_id, partner_id, context) - vals['value'].update({'tax_id':tax_id,'amount': amount}) + vals = {'value':{} } + if ttype in ('sale', 'purchase'): + vals = self.onchange_price(cr, uid, ids, line_ids, tax_id, partner_id, context) + vals['value'].update({'tax_id':tax_id,'amount': amount}) currency_id = False if journal.currency: currency_id = journal.currency.id @@ -1183,6 +1199,7 @@ class account_voucher(osv.osv): account_id = voucher_brw.partner_id.property_account_receivable.id else: account_id = voucher_brw.partner_id.property_account_payable.id + sign = voucher_brw.type == 'payment' and -1 or 1 move_line = { 'name': write_off_name or name, 'account_id': account_id, @@ -1191,7 +1208,7 @@ class account_voucher(osv.osv): 'date': voucher_brw.date, 'credit': diff > 0 and diff or 0.0, 'debit': diff < 0 and -diff or 0.0, - 'amount_currency': company_currency <> current_currency and voucher_brw.writeoff_amount or False, + 'amount_currency': company_currency <> current_currency and (sign * -1 * voucher_brw.writeoff_amount) or False, 'currency_id': company_currency <> current_currency and current_currency or False, 'analytic_account_id': voucher_brw.analytic_id and voucher_brw.analytic_id.id or False, } diff --git a/addons/account_voucher/account_voucher_view.xml b/addons/account_voucher/account_voucher_view.xml index 5e26c366778..f8bab444453 100644 --- a/addons/account_voucher/account_voucher_view.xml +++ b/addons/account_voucher/account_voucher_view.xml @@ -34,6 +34,7 @@ + account.voucher.form account.voucher diff --git a/addons/account_voucher/test/account_voucher.yml b/addons/account_voucher/test/account_voucher.yml index 2ea6c0b7890..f8e20f496e5 100644 --- a/addons/account_voucher/test/account_voucher.yml +++ b/addons/account_voucher/test/account_voucher.yml @@ -1,7 +1,8 @@ - In order to check account voucher module in OpenERP I create a customer voucher - - !record {model: account.voucher, id: account_voucher_voucherforaxelor0}: + !record {model: account.voucher, id: account_voucher_voucherforaxelor0, view: view_sale_receipt_form}: + type: sale account_id: account.cash amount: 1000.0 company_id: base.main_company @@ -47,7 +48,8 @@ - Now I create a Vendor Voucher - - !record {model: account.voucher, id: account_voucher_voucheraxelor0, view: False}: + !record {model: account.voucher, id: account_voucher_voucheraxelor0, view: view_voucher_filter_vendor}: + type: purchase account_id: account.cash amount: 1000.0 company_id: base.main_company diff --git a/addons/account_voucher/test/account_voucher_report.yml b/addons/account_voucher/test/account_voucher_report.yml index 3996e0c27e4..60dc4103553 100644 --- a/addons/account_voucher/test/account_voucher_report.yml +++ b/addons/account_voucher/test/account_voucher_report.yml @@ -1,7 +1,8 @@ - Demo for Account Voucher - - !record {model: account.voucher, id: account_voucher_voucheraxelor0again}: + !record {model: account.voucher, id: account_voucher_voucheraxelor0again, view: view_sale_receipt_form}: + type: sale account_id: account.cash company_id: base.main_company journal_id: account.bank_journal diff --git a/addons/account_voucher/test/case1_usd_usd.yml b/addons/account_voucher/test/case1_usd_usd.yml index b706e6f0644..300d565f229 100644 --- a/addons/account_voucher/test/case1_usd_usd.yml +++ b/addons/account_voucher/test/case1_usd_usd.yml @@ -216,6 +216,10 @@ assert move_line.credit == 63.00, "Debtor account has wrong entry." elif move_line.amount_currency == 10.00: assert move_line.debit == 9.00, "Writeoff amount is wrong." + elif move_line.amount_currency == 240.00: + assert move_line.debit == 216.00, "Bank entry is wrong." + else: + assert False, "Unrecognized journal entry" - I check the residual amount of Invoice1, should be 20 in amount_currency - @@ -237,7 +241,7 @@ - On the first April, I create the second voucher of payment with values 45 USD, journal USD, - - !record {model: account.voucher, id: account_voucher_2_case1}: + !record {model: account.voucher, id: account_voucher_2_case1, view: view_vendor_receipt_form}: account_id: account.cash amount: 45.0 company_id: base.main_company @@ -323,8 +327,16 @@ assert move_line.debit == 4.75, "Writeoff amount is wrong." elif move_line.debit == 11.5 and move_line.account_id.reconcile: assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_a, "Exchange difference entry for the invoice of 100$ is wrong" + elif move_line.credit == 11.5: + assert move_line.amount_currency == 0.0 elif move_line.debit == 31.0 and move_line.account_id.reconcile: assert move_line.amount_currency == 0.0 and move_line.reconcile_id.id == reconcile_b, "Exchange difference entry for the invoice of 200$ is wrong" + elif move_line.credit == 31.0: + assert move_line.amount_currency == 0.0 + elif move_line.amount_currency == 45.00: + assert move_line.debit == 42.75, "Bank entry is wrong." + else: + assert False, "Unrecognized journal entry" - I check the residual amount of Invoice1, should be 0 in residual currency and 0 in amount_residual and paid - diff --git a/addons/account_voucher/test/case4_cad_chf.yml b/addons/account_voucher/test/case4_cad_chf.yml index a78669c95ef..a2b252497cd 100644 --- a/addons/account_voucher/test/case4_cad_chf.yml +++ b/addons/account_voucher/test/case4_cad_chf.yml @@ -164,7 +164,7 @@ - I check that my currency rate difference is correct. 0 in debit with no amount_currency - - I check that my writeoff is correct. 11.05 credit and 13.26 amount_currency + I check that my writeoff is correct. 11.05 credit and -13.26 amount_currency - !python {model: account.voucher}: | voucher = self.search(cr, uid, [('name', '=', 'First payment: Case 4'), ('partner_id', '=', ref('base.res_partner_19'))]) @@ -179,7 +179,7 @@ elif move_line.debit == 0.00 and move_line.credit == 0.00: assert move_line.amount_currency == 0.00, "Incorrect Currency Difference." elif move_line.credit == 10.61: - assert move_line.amount_currency == 13.26, "Writeoff amount is wrong." + assert move_line.amount_currency == -13.26, "Writeoff amount is wrong." else: assert False, "Wrong entry" - diff --git a/addons/account_voucher/test/sales_receipt.yml b/addons/account_voucher/test/sales_receipt.yml index f39d784bd42..7cd82eecaff 100644 --- a/addons/account_voucher/test/sales_receipt.yml +++ b/addons/account_voucher/test/sales_receipt.yml @@ -1,7 +1,7 @@ - Creating a Voucher Receipt for partner Seagate with amount 30000.0 - - !record {model: account.voucher, id: account_voucher_seagate_0}: + !record {model: account.voucher, id: account_voucher_seagate_0, view: view_sale_receipt_form}: account_id: account.a_recv amount: 30000.0 company_id: base.main_company diff --git a/addons/account_voucher/voucher_sales_purchase_view.xml b/addons/account_voucher/voucher_sales_purchase_view.xml index 5bcecfa268e..4c388730644 100644 --- a/addons/account_voucher/voucher_sales_purchase_view.xml +++ b/addons/account_voucher/voucher_sales_purchase_view.xml @@ -72,6 +72,7 @@

+ @@ -80,9 +81,9 @@ + - @@ -235,6 +236,7 @@ widget="selection" on_change="onchange_journal(journal_id, line_dr_ids, tax_id, partner_id, date, amount, type, company_id, context)" groups="account.group_account_user"/> + diff --git a/addons/analytic/analytic.py b/addons/analytic/analytic.py index ff09349b8a2..1ce483a26cd 100644 --- a/addons/analytic/analytic.py +++ b/addons/analytic/analytic.py @@ -125,7 +125,8 @@ class account_analytic_account(osv.osv): if account.company_id: if account.company_id.currency_id.id != value: raise osv.except_osv(_('Error!'), _("If you set a company, the currency selected has to be the same as it's currency. \nYou can remove the company belonging, and thus change the currency, only on analytic account of type 'view'. This can be really usefull for consolidation purposes of several companies charts with different currencies, for example.")) - return cr.execute("""update account_analytic_account set currency_id=%s where id=%s""", (value, account.id, )) + if value: + return cr.execute("""update account_analytic_account set currency_id=%s where id=%s""", (value, account.id, )) def _currency(self, cr, uid, ids, field_name, arg, context=None): result = {} @@ -163,7 +164,7 @@ class account_analytic_account(osv.osv): 'date': fields.date('Date End', select=True), 'company_id': fields.many2one('res.company', 'Company', required=False), #not required because we want to allow different companies to use the same chart of account, except for leaf accounts. 'state': fields.selection([('template', 'Template'),('draft','New'),('open','In Progress'), ('cancelled', 'Cancelled'),('pending','To Renew'),('close','Closed')], 'Status', required=True,), - 'currency_id': fields.function(_currency, fnct_inv=_set_company_currency, + 'currency_id': fields.function(_currency, fnct_inv=_set_company_currency, #the currency_id field is readonly except if it's a view account and if there is no company store = { 'res.company': (_get_analytic_account, ['currency_id'], 10), }, string='Currency', type='many2one', relation='res.currency'), diff --git a/addons/analytic/analytic_view.xml b/addons/analytic/analytic_view.xml index 51f5428002f..0bb009e72b0 100644 --- a/addons/analytic/analytic_view.xml +++ b/addons/analytic/analytic_view.xml @@ -24,6 +24,7 @@ + diff --git a/addons/crm/crm_phonecall_view.xml b/addons/crm/crm_phonecall_view.xml index ea20624d738..c610913febf 100644 --- a/addons/crm/crm_phonecall_view.xml +++ b/addons/crm/crm_phonecall_view.xml @@ -140,6 +140,7 @@ + diff --git a/addons/event/event.py b/addons/event/event.py index 0eb2dda8312..d86fd92d054 100644 --- a/addons/event/event.py +++ b/addons/event/event.py @@ -435,22 +435,6 @@ class event_registration(osv.osv): 'phone':contact_id.phone, }} - def onchange_event(self, cr, uid, ids, event_id, context=None): - """This function returns value of Product Name, Unit Price based on Event. - """ - if context is None: - context = {} - if not event_id: - return {} - event_obj = self.pool.get('event.event') - data_event = event_obj.browse(cr, uid, event_id, context=context) - return {'value': - {'event_begin_date': data_event.date_begin, - 'event_end_date': data_event.date_end, - 'company_id': data_event.company_id and data_event.company_id.id or False, - } - } - def onchange_partner_id(self, cr, uid, ids, part, context=None): res_obj = self.pool.get('res.partner') data = {} diff --git a/addons/event/event_view.xml b/addons/event/event_view.xml index 6ad8fb20467..003072616f7 100644 --- a/addons/event/event_view.xml +++ b/addons/event/event_view.xml @@ -136,10 +136,22 @@ + + + + + + + + + + + + @@ -217,7 +229,7 @@ - + @@ -452,7 +464,7 @@