Skip to content

Commit

Permalink
[MERGE] forward port branch 11.0 up to 468dab6
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed Nov 15, 2018
2 parents f1e999d + 468dab6 commit 15f686e
Show file tree
Hide file tree
Showing 37 changed files with 327 additions and 199 deletions.
21 changes: 12 additions & 9 deletions addons/account/report/account_aged_partner_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def _get_partner_move_lines(self, account_type, date_from, target_move, period_l
res = []
total = []
cr = self.env.cr
company_ids = self.env.context.get('company_ids', (self.env.user.company_id.id,))
user_company = self.env.user.company_id
user_currency = user_company.currency_id
ResCurrency = self.env['res.currency'].with_context(date=date_from)
company_ids = self._context.get('company_ids') or [user_company.id]
move_state = ['draft', 'posted']
if target_move == 'posted':
move_state = ['posted']
Expand Down Expand Up @@ -99,15 +102,15 @@ def _get_partner_move_lines(self, account_type, date_from, target_move, period_l
partner_id = line.partner_id.id or False
if partner_id not in undue_amounts:
undue_amounts[partner_id] = 0.0
line_amount = line.balance
if line.balance == 0:
line_amount = ResCurrency._compute(line.company_id.currency_id, user_currency, line.balance)
if user_currency.is_zero(line_amount):
continue
for partial_line in line.matched_debit_ids:
if partial_line.max_date <= date_from:
line_amount += partial_line.amount
line_amount += ResCurrency._compute(partial_line.company_id.currency_id, user_currency, partial_line.amount)
for partial_line in line.matched_credit_ids:
if partial_line.max_date <= date_from:
line_amount -= partial_line.amount
line_amount -= ResCurrency._compute(partial_line.company_id.currency_id, user_currency, partial_line.amount)
if not self.env.user.company_id.currency_id.is_zero(line_amount):
undue_amounts[partner_id] += line_amount
lines[partner_id].append({
Expand Down Expand Up @@ -151,15 +154,15 @@ def _get_partner_move_lines(self, account_type, date_from, target_move, period_l
partner_id = line.partner_id.id or False
if partner_id not in partners_amount:
partners_amount[partner_id] = 0.0
line_amount = line.balance
if line.balance == 0:
line_amount = ResCurrency._compute(line.company_id.currency_id, user_currency, line.balance)
if user_currency.is_zero(line_amount):
continue
for partial_line in line.matched_debit_ids:
if partial_line.max_date <= date_from:
line_amount += partial_line.amount
line_amount += ResCurrency._compute(partial_line.company_id.currency_id, user_currency, partial_line.amount)
for partial_line in line.matched_credit_ids:
if partial_line.max_date <= date_from:
line_amount -= partial_line.amount
line_amount -= ResCurrency._compute(partial_line.company_id.currency_id, user_currency, partial_line.amount)

if not self.env.user.company_id.currency_id.is_zero(line_amount):
partners_amount[partner_id] += line_amount
Expand Down
2 changes: 0 additions & 2 deletions addons/account/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ access_account_journal_invoice,account.journal invoice,model_account_journal,acc
access_account_invoice_group_invoice,account.invoice group invoice,model_account_invoice,account.group_account_invoice,1,1,1,1
access_res_currency_account_manager,res.currency account manager,base.model_res_currency,group_account_manager,1,1,1,1
access_res_currency_rate_account_manager,res.currency.rate account manager,base.model_res_currency_rate,group_account_manager,1,1,1,1
access_account_invoice_user,account.invoice user,model_account_invoice,base.group_user,1,0,0,0
access_account_invoice_line_user,account.invoice.line user,model_account_invoice_line,base.group_user,1,0,0,0
access_account_invoice_portal,account.invoice.portal,account.model_account_invoice,base.group_portal,1,0,0,0
access_account_invoice_line_portal,account.invoice.line.portal,account.model_account_invoice_line,base.group_portal,1,0,0,0
access_account_payment_term_partner_manager,account.payment.term partner manager,model_account_payment_term,base.group_user,1,0,0,0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1208,8 +1208,9 @@ var ManualModel = StatementModel.extend({
});

var domainReconcile = [];
if (context && context.company_ids) {
domainReconcile.push(['company_id', 'in', context.company_ids]);
var company_ids = context && context.company_ids || [session.company_id]
if (company_ids) {
domainReconcile.push(['company_id', 'in', company_ids]);
}
var def_reconcileModel = this._rpc({
model: 'account.reconcile.model',
Expand Down
2 changes: 1 addition & 1 deletion addons/account/wizard/account_report_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def check_report(self):
data['form'] = self.read(['date_from', 'date_to', 'journal_ids', 'target_move', 'company_id'])[0]
used_context = self._build_contexts(data)
data['form']['used_context'] = dict(used_context, lang=self.env.context.get('lang') or 'en_US')
return self._print_report(data)
return self.with_context(discard_logo_check=True)._print_report(data)
8 changes: 4 additions & 4 deletions addons/account_asset/views/account_asset_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
attrs="{'invisible': [('type','!=','sale')]}"
style="font-weight: bold" class="o_light_label"/>
</div>
<field name="account_asset_id" nolabel="1" attrs="{'invisible': [('type','=', False)]}"/>
<field name="account_asset_id" nolabel="1" attrs="{'invisible': [('type','=', False)]}" domain="[('company_id', '=', company_id)]"/>
<div>
<label for="account_depreciation_id"
attrs="{'invisible': [('type','!=','purchase')]}"
Expand All @@ -42,7 +42,7 @@
attrs="{'invisible': [('type','!=','sale')]}"
style="font-weight: bold" class="o_light_label"/>
</div>
<field name="account_depreciation_id" nolabel="1"/>
<field name="account_depreciation_id" nolabel="1" domain="[('company_id', '=', company_id)]"/>
<div>
<label for="account_depreciation_expense_id"
attrs="{'invisible': [('type','!=','purchase')]}"
Expand All @@ -51,8 +51,8 @@
attrs="{'invisible': [('type','!=','sale')]}"
style="font-weight: bold" class="o_light_label"/>
</div>
<field name="account_depreciation_expense_id" nolabel="1"/>
<field name="account_analytic_id" groups="analytic.group_analytic_accounting"/>
<field name="account_depreciation_expense_id" nolabel="1" domain="[('company_id', '=', company_id)]"/>
<field name="account_analytic_id" domain="[('company_id', '=', company_id)]" groups="analytic.group_analytic_accounting"/>
</group>
<group string="Periodicity">
<field name="method_time" string="Time Method Based On" widget="radio" attrs="{'invisible': [('type','!=','purchase')]}"/>
Expand Down
8 changes: 4 additions & 4 deletions addons/auth_signup/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ def _get_signup_url_for_action(self, action=None, view_type=None, menu_id=None,
for partner in self:
# when required, make sure the partner has a valid signup token
if self.env.context.get('signup_valid') and not partner.user_ids:
partner.signup_prepare()
partner.sudo().signup_prepare()

route = 'login'
# the parameters to encode for the query
query = dict(db=self.env.cr.dbname)
signup_type = self.env.context.get('signup_force_type_in_url', partner.signup_type or '')
signup_type = self.env.context.get('signup_force_type_in_url', partner.sudo().signup_type or '')
if signup_type:
route = 'reset_password' if signup_type == 'reset' else signup_type

if partner.signup_token and signup_type:
query['token'] = partner.signup_token
if partner.sudo().signup_token and signup_type:
query['token'] = partner.sudo().signup_token
elif partner.user_ids:
query['login'] = partner.user_ids[0].login
else:
Expand Down
58 changes: 49 additions & 9 deletions addons/base_address_city/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,58 @@ def _fields_view_get_address(self, arch):
# render the partner address accordingly to address_view_id
doc = etree.fromstring(arch)
if doc.xpath("//field[@name='city_id']"):
return arch
label = _('City')
for city_node in doc.xpath("//field[@name='city']"):
replacement_xml = """
return arch

replacement_xml = """
<div>
<field name="country_enforce_cities" invisible="1"/>
<field name='city' placeholder="%s" attrs="{'invisible': [('country_enforce_cities', '=', True), ('city_id', '!=', False)], 'readonly': [('type', '=', 'contact'), ('parent_id', '!=', False)]}"/>
<field name='city_id' placeholder="%s" string="%s" attrs="{'invisible': [('country_enforce_cities', '=', False)], 'readonly': [('type', '=', 'contact'), ('parent_id', '!=', False)]}" context="{'default_country_id': country_id}" domain="[('country_id', '=', country_id)]"/>
<field name='city' placeholder="%(placeholder)s"
attrs="{
'invisible': [('country_enforce_cities', '=', True), ('city_id', '!=', False)],
'readonly': [('type', '=', 'contact')%(parent_condition)s]
}"
/>
<field name='city_id' placeholder="%(placeholder)s" string="%(placeholder)s"
context="{'default_country_id': country_id}"
domain="[('country_id', '=', country_id)]"
attrs="{
'invisible': [('country_enforce_cities', '=', False)],
'readonly': [('type', '=', 'contact')%(parent_condition)s]
}"
/>
</div>
""" % (label, label, label)
city_id_node = etree.fromstring(replacement_xml)
city_node.getparent().replace(city_node, city_id_node)
"""

replacement_data = {
'placeholder': _('City'),
}

def _arch_location(node):
in_subview = False
view_type = False
parent = node.getparent()
while parent is not None and (not view_type or not in_subview):
if parent.tag == 'field':
in_subview = True
elif parent.tag in ['list', 'tree', 'kanban', 'form']:
view_type = parent.tag
parent = parent.getparent()
return {
'view_type': view_type,
'in_subview': in_subview,
}

for city_node in doc.xpath("//field[@name='city']"):
location = _arch_location(city_node)
replacement_data['parent_condition'] = ''
if location['view_type'] == 'form' or not location['in_subview']:
replacement_data['parent_condition'] = ", ('parent_id', '!=', False)"

replacement_formatted = replacement_xml % replacement_data
for replace_node in etree.fromstring(replacement_formatted).getchildren():
city_node.addprevious(replace_node)
parent = city_node.getparent()
parent.remove(city_node)

arch = etree.tostring(doc, encoding='unicode')
return arch
10 changes: 9 additions & 1 deletion addons/calendar/models/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,15 @@ def _sync_activities(self, values):
if values.get('description'):
activity_values['note'] = values['description']
if values.get('start'):
activity_values['date_deadline'] = fields.Datetime.from_string(values['start']).date()
# self.start is a datetime UTC *only when the event is not allday*
# activty.date_deadline is a date (No TZ, but should represent the day in which the user's TZ is)
# See 72254129dbaeae58d0a2055cba4e4a82cde495b7 for the same issue, but elsewhere
deadline = fields.Datetime.from_string(values['start'])
user_tz = self.env.context.get('tz')
if user_tz and not self.allday:
deadline = pytz.UTC.localize(deadline)
deadline = deadline.astimezone(pytz.timezone(user_tz))
activity_values['date_deadline'] = deadline.date()
if values.get('user_id'):
activity_values['user_id'] = values['user_id']
if activity_values.keys():
Expand Down
70 changes: 70 additions & 0 deletions addons/calendar/tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,73 @@ def test_recurring_around_dst(self):
else:
self.assertEqual(d.hour, 15)
self.assertEqual(d.minute, 30)

def test_event_activity_timezone(self):
activty_type = self.env['mail.activity.type'].create({
'name': 'Meeting',
'category': 'meeting'
})

activity_id = self.env['mail.activity'].create({
'summary': 'Meeting with partner',
'activity_type_id': activty_type.id,
'res_model_id': self.env['ir.model'].search([('model', '=', 'res.partner')], limit=1).id,
'res_id': self.env['res.partner'].search([('name', 'ilike', 'Agrolait')], limit=1).id,
})

calendar_event = self.env['calendar.event'].create({
'name': 'Meeting with partner',
'activity_ids': [(6, False, activity_id.ids)],
'start': '2018-11-12 21:00:00',
'stop': '2018-11-13 00:00:00',
})

# Check output in UTC
self.assertEqual(activity_id.date_deadline, '2018-11-12')

# Check output in the user's tz
# write on the event to trigger sync of activities
calendar_event.with_context({'tz': 'Australia/Brisbane'}).write({
'start': '2018-11-12 21:00:00',
})

self.assertEqual(activity_id.date_deadline, '2018-11-13')

def test_event_allday_activity_timezone(self):
# Covers use case of commit eef4c3b48bcb4feac028bf640b545006dd0c9b91
# Also, read the comment in the code at calendar.event._inverse_dates
activty_type = self.env['mail.activity.type'].create({
'name': 'Meeting',
'category': 'meeting'
})

activity_id = self.env['mail.activity'].create({
'summary': 'Meeting with partner',
'activity_type_id': activty_type.id,
'res_model_id': self.env['ir.model'].search([('model', '=', 'res.partner')], limit=1).id,
'res_id': self.env['res.partner'].search([('name', 'ilike', 'Agrolait')], limit=1).id,
})

calendar_event = self.env['calendar.event'].create({
'name': 'All Day',
'start': "2018-10-16 00:00:00",
'start_date': "2018-10-16",
'start_datetime': False,
'stop': "2018-10-18 00:00:00",
'stop_date': "2018-10-18",
'stop_datetime': False,
'allday': True,
'activity_ids': [(6, False, activity_id.ids)],
})

# Check output in UTC
self.assertEqual(activity_id.date_deadline, '2018-10-16')

# Check output in the user's tz
# write on the event to trigger sync of activities
calendar_event.with_context({'tz': 'Pacific/Honolulu'}).write({
'start': '2018-10-16 00:00:00',
'start_date': '2018-10-16',
})

self.assertEqual(activity_id.date_deadline, '2018-10-16')
2 changes: 1 addition & 1 deletion addons/delivery/models/delivery_carrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def fixed_rate_shipment(self, order):
'error_message': _('Error: this delivery method is not available for this address.'),
'warning_message': False}
price = self.fixed_price
if self.company_id.currency_id.id != order.currency_id.id:
if self.company_id and self.company_id.currency_id.id != order.currency_id.id:
price = self.env['res.currency']._compute(self.company_id.currency_id, order.currency_id, price)
return {'success': True,
'price': price,
Expand Down
15 changes: 15 additions & 0 deletions addons/mail/static/src/js/chatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ var Chatter = Widget.extend({
this.composer.clear_composer();
}
},
/**
* @private
*/
_disableComposer: function () {
this.$(".o_composer_button_send").prop('disabled', true);
},
/**
* @private
*/
_enableComposer: function () {
this.$(".o_composer_button_send").prop('disabled', false);
},
/**
* Discard changes on the record.
*
Expand Down Expand Up @@ -231,12 +243,15 @@ var Chatter = Widget.extend({
self.composer.focus();
}
self.composer.on('post_message', self, function (message) {
self._disableComposer();
self._discardOnReload(message).then(function () {
self.fields.thread.postMessage(message).then(function () {
self._closeComposer(true);
if (self._reloadAfterPost(message)) {
self.trigger_up('reload');
}
}).fail(function () {
self._enableComposer();
});
});
});
Expand Down
3 changes: 0 additions & 3 deletions addons/mail/static/src/js/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,10 @@ var BasicComposer = Widget.extend({
},

send_message: function () {
var $button = this.$('.o_composer_button_send');

if (this.is_empty() || !this.do_check_attachment_upload()) {
return;
}

$button.prop('disabled', true);
clearTimeout(this.canned_timeout);
var self = this;
this.preprocess_message().then(function (message) {
Expand Down
2 changes: 2 additions & 0 deletions addons/point_of_sale/static/src/css/pos.css
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ td {
display: flex;
-webkit-flex: 1;
flex: 1;
max-width: -moz-available;
max-width: -webkit-fill-available;
}
.pos .orders {
display: -webkit-flex;
Expand Down
6 changes: 4 additions & 2 deletions addons/pos_restaurant/static/src/js/multiprint.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ models.Orderline = models.Orderline.extend({
}
},
set_dirty: function(dirty) {
this.mp_dirty = dirty;
this.trigger('change',this);
if (this.mp_dirty !== dirty) {
this.mp_dirty = dirty;
this.trigger('change', this);
}
},
get_line_diff_hash: function(){
if (this.get_note()) {
Expand Down
2 changes: 1 addition & 1 deletion addons/product/report/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_report_values(self, docids, data=None):
quantities = self._get_quantity(data)
return {
'doc_ids': data.get('ids', data.get('active_ids')),
'doc_model': 'hr.contribution.register',
'doc_model': 'product.pricelist',
'docs': products,
'data': dict(
data,
Expand Down
12 changes: 12 additions & 0 deletions addons/purchase_requisition/models/purchase_requisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,3 +481,15 @@ def _get_upstream_documents_and_responsibles(self, visited):
return [(requisition_line.requisition_id, requisition_line.requisition_id.user_id, visited) for requisition_line in self.requisition_line_ids if requisition_line.state not in ('done', 'cancel')]
else:
return super(StockMove, self)._get_upstream_documents_and_responsibles(visited)


class Orderpoint(models.Model):
_inherit = "stock.warehouse.orderpoint"

def _quantity_in_progress(self):
res = super(Orderpoint, self)._quantity_in_progress()
for op in self:
for pr in self.env['purchase.requisition'].search([('state','=','draft'),('origin','=',op.name)]):
for prline in pr.line_ids.filtered(lambda l: l.product_id.id == op.product_id.id):
res[op.id] += prline.product_uom_id._compute_quantity(prline.product_qty, op.product_uom, round=False)
return res
Loading

0 comments on commit 15f686e

Please sign in to comment.