[MERGE] forward port branch saas-15 up to cad0be27e7

This commit is contained in:
Christophe Simonis
2019-05-28 15:04:40 +02:00
5 changed files with 35 additions and 18 deletions
+24 -15
View File
@@ -173,6 +173,25 @@ class HrExpense(models.Model):
total_currency -= line['amount_currency'] or line['price']
return total, total_currency, account_move_lines
@api.multi
def _prepare_move_values(self):
"""
This function prepares move values related to an expense
"""
self.ensure_one()
journal = self.sheet_id.bank_journal_id if self.payment_mode == 'company_account' else self.sheet_id.journal_id
acc_date = self.sheet_id.accounting_date or self.date
move_values = {
'journal_id': journal.id,
'company_id': self.env.user.company_id.id,
'date': acc_date,
'ref': self.sheet_id.name,
# force the name to the default value, to avoid an eventual 'default_name' in the context
# to set it to '' which cause no number to be given to the account.move when posted.
'name': '/',
}
return move_values
@api.multi
def action_move_create(self):
'''
@@ -180,19 +199,9 @@ class HrExpense(models.Model):
'''
move_group_by_sheet = {}
for expense in self:
journal = expense.sheet_id.bank_journal_id if expense.payment_mode == 'company_account' else expense.sheet_id.journal_id
#create the move that will contain the accounting entries
acc_date = expense.sheet_id.accounting_date or expense.date
if not expense.sheet_id.id in move_group_by_sheet:
move = self.env['account.move'].create({
'journal_id': journal.id,
'company_id': self.env.user.company_id.id,
'date': acc_date,
'ref': expense.sheet_id.name,
# force the name to the default value, to avoid an eventual 'default_name' in the context
# to set it to '' which cause no number to be given to the account.move when posted.
'name': '/',
})
# create the move that will contain the accounting entries
if expense.sheet_id.id not in move_group_by_sheet:
move = self.env['account.move'].create(expense._prepare_move_values())
move_group_by_sheet[expense.sheet_id.id] = move
else:
move = move_group_by_sheet[expense.sheet_id.id]
@@ -203,7 +212,7 @@ class HrExpense(models.Model):
#create one more move line, a counterline for the total on payable account
payment_id = False
total, total_currency, move_lines = expense._compute_expense_totals(company_currency, move_lines, acc_date)
total, total_currency, move_lines = expense._compute_expense_totals(company_currency, move_lines, move.date)
if expense.payment_mode == 'company_account':
if not expense.sheet_id.bank_journal_id.default_credit_account_id:
raise UserError(_("No credit account found for the %s journal, please configure one.") % (expense.sheet_id.bank_journal_id.name))
@@ -236,7 +245,7 @@ class HrExpense(models.Model):
'name': aml_name,
'price': total,
'account_id': emp_account,
'date_maturity': acc_date,
'date_maturity': move.date,
'amount_currency': diff_currency_p and total_currency or False,
'currency_id': diff_currency_p and expense.currency_id.id or False,
'payment_id': payment_id,
+4
View File
@@ -437,6 +437,10 @@ class ProductTemplate(models.Model):
def _is_cost_method_standard(self):
return True
@api.depends(
'product_variant_ids',
'product_variant_ids.stock_quant_ids',
)
def _compute_quantities(self):
res = self._compute_quantities_dict()
for template in self:
+1
View File
@@ -27,3 +27,4 @@ Thomas Binsfeld thomas.binsfeld@acsone.eu https://github.com/ThomasBinsfeld
Benjamin Willig benjamin.willig@acsone.eu https://github.com/benwillig
François Honoré francois.honore@acsone.eu https://github.com/acsonefho
Denis Robinet denis.robinet@acsone.eu https://github.com/RobinetDenisAcsone
Benoit Aimont benoit.aimont@acsone.eu https://github.com/baimont
@@ -209,11 +209,12 @@ class TestFields(common.TransactionCase):
self.assertEqual(c.display_name, 'B / C')
self.assertEqual(d.display_name, 'B / C / D')
b.name = 'X'
# rename several records to trigger several recomputations at once
(d + c + b).write({'name': 'X'})
self.assertEqual(a.display_name, 'A')
self.assertEqual(b.display_name, 'X')
self.assertEqual(c.display_name, 'X / C')
self.assertEqual(d.display_name, 'X / C / D')
self.assertEqual(c.display_name, 'X / X')
self.assertEqual(d.display_name, 'X / X / X')
# delete b; both c and d are deleted in cascade; c should also be marked
# to recompute, but recomputation should not fail...
+2
View File
@@ -1032,6 +1032,8 @@ class Field(MetaField('DummyField', (object,), {})):
recs = record._recompute_check(self)
if recs:
# recompute the value (only in cache)
if self.recursive:
recs = record
self.compute_value(recs)
# HACK: if result is in the wrong cache, copy values
if recs.env != env: