diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 6914aafc6cb..1850797ca04 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -1083,10 +1083,13 @@ class AccountMoveLine(models.Model):
# the provided values were not already multi-currency
if account.currency_id and 'amount_currency' not in vals and account.currency_id.id != account.company_id.currency_id.id:
vals['currency_id'] = account.currency_id.id
- ctx = {}
- if 'date' in vals:
- ctx['date'] = vals['date']
- vals['amount_currency'] = account.company_id.currency_id.with_context(ctx).compute(amount, account.currency_id)
+ if self._context.get('skip_full_reconcile_check') == 'amount_currency_excluded':
+ vals['amount_currency'] = 0.0
+ else:
+ ctx = {}
+ if 'date' in vals:
+ ctx['date'] = vals['date']
+ vals['amount_currency'] = account.company_id.currency_id.with_context(ctx).compute(amount, account.currency_id)
if not ok:
raise UserError(_('You cannot use this general account in this journal, check the tab \'Entry Controls\' on the related journal.'))
diff --git a/addons/account_asset/account_asset.py b/addons/account_asset/account_asset.py
index b8727bbe76c..745358e67b9 100644
--- a/addons/account_asset/account_asset.py
+++ b/addons/account_asset/account_asset.py
@@ -372,7 +372,7 @@ class AccountAssetAsset(models.Model):
@api.multi
def _compute_entries(self, date, group_entries=False):
- depreciation_ids = self.env['account.asset.depreciation.line'].with_context(depreciation_date=date).search([
+ depreciation_ids = self.env['account.asset.depreciation.line'].search([
('asset_id', 'in', self.ids), ('depreciation_date', '<=', date),
('move_check', '=', False)])
if group_entries:
diff --git a/addons/account_asset/i18n/account_asset.pot b/addons/account_asset/i18n/account_asset.pot
index 36cb901c308..d7effc2ba4d 100644
--- a/addons/account_asset/i18n/account_asset.pot
+++ b/addons/account_asset/i18n/account_asset.pot
@@ -460,6 +460,7 @@ msgstr ""
#. module: account_asset
#: model:ir.model.fields,field_description:account_asset.field_account_asset_category_account_depreciation_id
+#: model:ir.ui.view,arch_db:account_asset.view_account_asset_asset_form
msgid "Depreciation Entries: Asset Account"
msgstr ""
diff --git a/addons/account_asset/views/account_asset_view.xml b/addons/account_asset/views/account_asset_view.xml
index 1c9c07ab107..76921306a90 100644
--- a/addons/account_asset/views/account_asset_view.xml
+++ b/addons/account_asset/views/account_asset_view.xml
@@ -29,7 +29,7 @@
I agree that by signing this proposal, I - accept it on the behalf of , for an amount of + accept it on the behalf of , for an amount of with payment terms: . @@ -321,7 +321,7 @@
I agree that by paying this proposal, I - accept it on the behalf of , for an amount of + accept it on the behalf of , for an amount of with payment terms: . diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py index b3b2793402f..d76e0a94d4c 100644 --- a/addons/website_sale/models/product.py +++ b/addons/website_sale/models/product.py @@ -161,7 +161,6 @@ class Product(models.Model): taxes = partner.property_account_position_id.map_tax(self.taxes_id) return taxes.compute_all(public and self.lst_price or self.with_context(context).price, pricelist.currency_id, qty, product=self, partner=partner)[ret] - class ProductAttribute(models.Model): _inherit = "product.attribute" diff --git a/openerp/addons/test_new_api/tests/__init__.py b/openerp/addons/test_new_api/tests/__init__.py index 81aead1b05d..1e998327ab8 100644 --- a/openerp/addons/test_new_api/tests/__init__.py +++ b/openerp/addons/test_new_api/tests/__init__.py @@ -5,6 +5,7 @@ from . import test_new_fields from . import test_onchange from . import test_field_conversions from . import test_attributes +from . import test_one2many from . import test_ui from . import test_no_infinite_recursion from . import test_domain diff --git a/openerp/addons/test_new_api/tests/test_onchange.py b/openerp/addons/test_new_api/tests/test_onchange.py index 8516f9394e2..88e481c3052 100644 --- a/openerp/addons/test_new_api/tests/test_onchange.py +++ b/openerp/addons/test_new_api/tests/test_onchange.py @@ -176,7 +176,7 @@ class TestOnChange(common.TransactionCase): self.assertEqual(values, { 'name': partner.name, 'partner': partner.id, - 'lines': [(5,), (4, line.id)], + 'lines': [(6, 0, [line.id])], }) # modify 'partner' diff --git a/openerp/addons/test_new_api/tests/test_one2many.py b/openerp/addons/test_new_api/tests/test_one2many.py new file mode 100644 index 00000000000..38dee13ab54 --- /dev/null +++ b/openerp/addons/test_new_api/tests/test_one2many.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +from openerp.tests.common import TransactionCase + + +class One2manyCase(TransactionCase): + def setUp(self): + super(One2manyCase, self).setUp() + self.Line = self.env["test_new_api.multi.line"] + self.multi = self.env["test_new_api.multi"].create({ + "name": "What is up?" + }) + + def operations(self): + """Run operations on o2m fields to check all works fine.""" + # Check the lines first + self.assertItemsEqual( + self.multi.lines.mapped('name'), + map(str, range(10))) + # Modify the first line and drop the last one + self.multi.lines[0].name = "hello" + self.multi.lines = self.multi.lines[:-1] + self.assertEqual(len(self.multi.lines), 9) + self.assertIn("hello", self.multi.lines.mapped('name')) + # Invalidate the cache and check again; this crashes if the value + # of self.multi.lines in cache contains new records + self.multi.invalidate_cache() + self.assertEqual(len(self.multi.lines), 9) + self.assertIn("hello", self.multi.lines.mapped('name')) + + def test_new_one_by_one(self): + """Check lines created with ``new()`` and appended one by one.""" + for name in range(10): + self.multi.lines |= self.Line.new({"name": str(name)}) + self.operations() + + def test_new_single(self): + """Check lines created with ``new()`` and added in one step.""" + self.multi.lines = self.Line.browse( + [self.Line.new({"name": str(name)}).id for name in range(10)] + ) + self.operations() + + def test_create_one_by_one(self): + """Check lines created with ``create()`` and appended one by one.""" + for name in range(10): + self.multi.lines |= self.Line.create({"name": str(name)}) + self.operations() + + def test_create_single(self): + """Check lines created with ``create()`` and added in one step.""" + self.multi.lines = self.Line.browse( + [self.Line.create({"name": str(name)}).id for name in range(10)] + ) + self.operations() + + def test_rpcstyle_one_by_one(self): + """Check lines created with RPC style and appended one by one.""" + for name in range(10): + self.multi.lines = [(0, 0, {"name": str(name)})] + self.operations() + + def test_rpcstyle_single(self): + """Check lines created with RPC style and added in one step""" + self.multi.lines = [(0, 0, {'name': str(name)}) for name in range(10)] + self.operations() diff --git a/openerp/fields.py b/openerp/fields.py index a22a348c1e1..932917fa798 100644 --- a/openerp/fields.py +++ b/openerp/fields.py @@ -871,10 +871,12 @@ class Field(object): env.invalidate(spec) else: - # simply write to the database, and update cache + # Write to database write_value = self.convert_to_write(self.convert_to_record(value, record), record) record.write({self.name: write_value}) - record._cache[self] = value + # Update the cache unless value contains a new record + if not (self.relational and not all(value)): + record._cache[self] = value ############################################################################ # @@ -1835,7 +1837,7 @@ class _RelationalMulti(_Relational): def convert_to_write(self, value, record): # make result with new and existing records - result = [(5,)] + result = [(6, 0, [])] for record in value: if not record.id: values = {name: record[name] for name in record._cache} @@ -1846,7 +1848,7 @@ class _RelationalMulti(_Relational): values = record._convert_to_write(values) result.append((1, record.id, values)) else: - result.append((4, record.id)) + result[0][2].append(record.id) return result def convert_to_onchange(self, value, record, fnames=()): diff --git a/openerp/models.py b/openerp/models.py index 6329d30cbd7..071ea2da916 100644 --- a/openerp/models.py +++ b/openerp/models.py @@ -3890,8 +3890,7 @@ class BaseModel(object): ``(6, _, ids)`` replaces all existing records in the set by the ``ids`` list, equivalent to using the command ``5`` followed by a command - ``4`` for each ``id`` in ``ids``. Can not be used on - :class:`~openerp.fields.One2many`. + ``4`` for each ``id`` in ``ids``. .. note:: Values marked as ``_`` in the list above are ignored and can be anything, generally ``0`` or ``False``. diff --git a/openerp/osv/fields.py b/openerp/osv/fields.py index 5a1bd99c5d2..3033de679d0 100644 --- a/openerp/osv/fields.py +++ b/openerp/osv/fields.py @@ -877,7 +877,11 @@ class one2many(_column): ids2 = act[2] or [0] cr.execute('select id from '+_table+' where '+self._fields_id+'=%s and id <> ALL (%s)', (id,ids2)) ids3 = map(lambda x:x[0], cr.fetchall()) - obj.write(cr, user, ids3, {self._fields_id:False}, context=context or {}) + inverse_field = obj._fields.get(self._fields_id) + if getattr(inverse_field, "ondelete", None) == "cascade": + obj.unlink(cr, user, ids3, context=context) + else: + obj.write(cr, user, ids3, {self._fields_id: False}, context=context or {}) return result def search(self, cr, obj, args, name, value, offset=0, limit=None, uid=None, operator='like', context=None):