[PATCH] Upstream patch - 02022022

This commit is contained in:
Parthiv Patel
2022-02-02 02:16:46 +00:00
parent 9deedcd13a
commit dc31f854e2
7 changed files with 60 additions and 33 deletions
@@ -455,6 +455,11 @@ class AccountPaymentRegister(models.TransientModel):
"The register payment wizard should only be called on account.move or account.move.line records."
))
if 'journal_id' in res and not self.env['account.journal'].browse(res['journal_id'])\
.filtered_domain([('company_id', '=', lines.company_id.id), ('type', 'in', ('bank', 'cash'))]):
# default can be inherited from the list view, should be computed instead
del res['journal_id']
# Keep lines having a residual amount to pay.
available_lines = self.env['account.move.line']
for line in lines:
@@ -210,8 +210,7 @@ class AccountEdiFormat(models.Model):
invoice.move_type = default_move_type
# self could be a single record (editing) or be empty (new).
with Form(invoice.with_context(default_move_type=default_move_type,
account_predictive_bills_disable_prediction=True)) as invoice_form:
with Form(invoice.with_context(default_move_type=default_move_type)) as invoice_form:
self_ctx = self.with_company(invoice.company_id)
# Partner (first step to avoid warning 'Warning! You must first select a partner.').
@@ -57,7 +57,7 @@ class AccountEdiFormat(models.Model):
def _find_value(xpath, element=tree):
return self._find_value(xpath, element, namespaces)
with Form(invoice.with_context(account_predictive_bills_disable_prediction=True)) as invoice_form:
with Form(invoice) as invoice_form:
self_ctx = self.with_company(invoice.company_id.id)
# Reference
@@ -276,8 +276,7 @@ class AccountEdiFormat(models.Model):
# Setup the context for the Invoice Form
invoice_ctx = invoice.with_company(company) \
.with_context(default_move_type=move_type,
account_predictive_bills_disable_prediction=True)
.with_context(default_move_type=move_type)
# move could be a single record (editing) or be empty (new).
with Form(invoice_ctx) as invoice_form:
+10 -4
View File
@@ -2611,10 +2611,7 @@ class MailThread(models.AbstractModel):
for group_name, group_func, group_data in groups:
group_data.setdefault('notification_group_name', group_name)
group_data.setdefault('notification_is_customer', False)
is_thread_notification = msg_vals and (
msg_vals.get('model', self._name) != 'mail.thread' and
(msg_vals.get('res_id', self.ids[0] if self.ids else False) is not False)
)
is_thread_notification = self._notify_get_recipients_thread_info(msg_vals=msg_vals)['is_thread_notification']
group_data.setdefault('has_button_access', is_thread_notification)
group_button_access = group_data.setdefault('button_access', {})
group_button_access.setdefault('url', access_link)
@@ -2636,6 +2633,15 @@ class MailThread(models.AbstractModel):
return result
def _notify_get_recipients_thread_info(self, msg_vals=None):
""" Tool method to compute thread info used in ``_notify_classify_recipients``
and its sub-methods. """
res_model = msg_vals['model'] if msg_vals and 'model' in msg_vals else self._name
res_id = msg_vals['res_id'] if msg_vals and 'res_id' in msg_vals else self.ids[0] if self.ids else False
return {
'is_thread_notification': res_model and (res_model != 'mail.thread') and res_id
}
@api.model
def _notify_get_reply_to_on_records(self, default=None, records=None, company=None, doc_names=None):
""" Moved to ``BaseModel._notify_get_reply_to()`` """
+8 -2
View File
@@ -143,7 +143,7 @@ class PosOrder(models.Model):
pos_order._create_order_picking()
if pos_order.to_invoice and pos_order.state == 'paid':
pos_order.action_pos_order_invoice()
pos_order._generate_pos_order_invoice()
return pos_order.id
@@ -494,8 +494,14 @@ class PosOrder(models.Model):
else False
}
return vals
def action_pos_order_invoice(self):
self.write({'to_invoice': True})
res = self._generate_pos_order_invoice()
if self.company_id.anglo_saxon_accounting and self.session_id.update_stock_at_closing:
self._create_order_picking()
return res
def _generate_pos_order_invoice(self):
moves = self.env['account.move']
for order in self:
+34 -22
View File
@@ -130,6 +130,40 @@ class TestMessagePost(TestMailCommon, TestRecipients):
self.assertNotIn('body', emp_info['button_access']['url'])
self.assertNotIn('subject', emp_info['button_access']['url'])
# test when notifying on non-records (e.g. MailThread._message_notify())
for model, res_id in ((self.test_record._name, False),
(self.test_record._name, 0), # browse(0) does not return a valid recordset
(False, self.test_record.id),
(False, False),
('mail.thread', False),
('mail.thread', self.test_record.id)):
msg_vals.update({
'model': model,
'res_id': res_id,
})
# note that msg_vals wins over record on which method is called
notify_msg_vals = dict(msg_vals, **link_vals)
classify_res = self.test_record._notify_classify_recipients(
pdata, 'Test', msg_vals=notify_msg_vals)
# find back information for partner
partner_info = next(item for item in classify_res if item['recipients'] == self.partner_1.ids)
emp_info = next(item for item in classify_res if item['recipients'] == self.partner_employee.ids)
# check there is no access button
self.assertFalse(partner_info['has_button_access'])
self.assertFalse(emp_info['has_button_access'])
# test on falsy records (False model cannot be browsed, skipped)
if model:
record_falsy = self.env[model].browse(res_id)
classify_res = record_falsy._notify_classify_recipients(
pdata, 'Test', msg_vals=notify_msg_vals)
# find back information for partner
partner_info = next(item for item in classify_res if item['recipients'] == self.partner_1.ids)
emp_info = next(item for item in classify_res if item['recipients'] == self.partner_employee.ids)
# check there is no access button
self.assertFalse(partner_info['has_button_access'])
self.assertFalse(emp_info['has_button_access'])
@mute_logger('flectra.addons.mail.models.mail_mail')
def test_post_needaction(self):
(self.user_employee | self.user_admin).write({'notification_type': 'inbox'})
@@ -430,25 +464,3 @@ class TestMessagePost(TestMailCommon, TestRecipients):
subject='About %s' % test_record.name,
body_content=test_record.name,
attachments=[('first.txt', b'My first attachment', 'text/plain'), ('second.txt', b'My second attachment', 'text/plain')])
@mute_logger('flectra.addons.mail.models.mail_mail')
def test_post_notify_no_button(self):
pdata = self._generate_notify_recipients(self.partner_employee)
msg_vals = {
'body': 'Message body',
'model': False,
'res_id': False,
'subject': 'Message subject',
}
link_vals = {
'token': 'token_val',
'access_token': 'access_token_val',
'auth_signup_token': 'auth_signup_token_val',
'auth_login': 'auth_login_val',
}
notify_msg_vals = dict(msg_vals, **link_vals)
classify_res = self.env[self.test_record._name]._notify_classify_recipients(pdata, 'Test', msg_vals=notify_msg_vals)
# find back information for partner
partner_info = next(item for item in classify_res)
# check there is sno access button
self.assertFalse(partner_info['has_button_access'])