[ADD] lunch: order generates an email for the supplier
Confirming orders must now be done per supplier and will open an email composition wizard with the different orders
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
'name': 'Lunch',
|
||||
'sequence': 120,
|
||||
'version': '1.0',
|
||||
'depends': ['base', 'web', 'decimal_precision'],
|
||||
'depends': ['decimal_precision', 'mail'],
|
||||
'category': 'Human Resources',
|
||||
'summary': 'Handle lunch orders of your employees',
|
||||
'description': """
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="lunch_order_line_action_order" model="ir.actions.server">
|
||||
<field name="name">Lunch: Order meals</field>
|
||||
<field name="model_id" ref="model_lunch_order_line"/>
|
||||
@@ -7,7 +8,7 @@
|
||||
<field name="state">code</field>
|
||||
<field name="code">
|
||||
if records:
|
||||
records.order()
|
||||
action = records.order()
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -26,5 +27,121 @@ if records:
|
||||
<field name="state">code</field>
|
||||
<field name="code">records.cancel()</field>
|
||||
</record>
|
||||
</data>
|
||||
<data noupdate="0">
|
||||
<record id="lunch_order_mail_supplier" model="mail.template">
|
||||
<field name="name">Lunch: Send by email</field>
|
||||
<field name="model_id" ref="lunch.model_lunch_order"/>
|
||||
<field name="email_from">${ctx['order']['supplier_email'] |safe}</field>
|
||||
<field name="partner_to">${ctx['order']['supplier_id']}</field>
|
||||
<field name="subject">Orders for ${ctx['order']['company_name']}</field>
|
||||
<field name="body_html" type="html">
|
||||
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"><tr><td align="center">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="590" style="padding: 16px; background-color: white; color: #454748; border-collapse:separate;">
|
||||
<tbody>
|
||||
<!-- HEADER -->
|
||||
<tr>
|
||||
<td align="center" style="min-width: 590px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;">
|
||||
<tr><td valign="middle">
|
||||
<span style="font-size: 10px;">Lunch Order</span><br/>
|
||||
</td><td valign="middle" align="right">
|
||||
<img src="/logo.png?company=${user.company_id.id}" style="padding: 0px; margin: 0px; height: auto; width: 80px;" t-att-alt="'%s' % company.name"/>
|
||||
</td></tr>
|
||||
<tr><td colspan="2" style="text-align:center;">
|
||||
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin:16px 0px 16px 0px;"/>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- CONTENT -->
|
||||
<tr>
|
||||
<td align="center" style="min-width: 590px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; padding: 0px 8px 0px 8px; border-collapse:separate;">
|
||||
<tr>
|
||||
<td valign="top" style="font-size: 13px;">
|
||||
<div>
|
||||
% set lines = ctx['lines']
|
||||
% set order = ctx['order']
|
||||
% set supplier = user.env['res.partner'].browse(order['supplier_id'])
|
||||
% set currency = user.env['res.currency'].browse(order['currency_id'])
|
||||
<p>
|
||||
Dear ${order['supplier_name']},
|
||||
</p><p>
|
||||
Here is, today orders for ${order['company_name']}:
|
||||
</p>
|
||||
|
||||
<ul>
|
||||
% for line in lines:
|
||||
<li>
|
||||
<strong>
|
||||
${line['product']}
|
||||
(x${line['quantity']})
|
||||
</strong>
|
||||
% if line['note']:
|
||||
<em>(${line['note']})</em>
|
||||
% endif
|
||||
<div style="display: inline-block; float:right">
|
||||
${format_amount(line['price'], currency)}
|
||||
</div>
|
||||
</li>
|
||||
% endfor
|
||||
</ul>
|
||||
|
||||
<p>Amounting in <strong>${format_amount(order['amount_total'], currency)}</strong>.</p>
|
||||
<p>Do not hesitate to contact us if you have any question.</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align:center;">
|
||||
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 16px 0px;"/>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- FOOTER -->
|
||||
<tr>
|
||||
<td align="center" style="min-width: 590px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: white; font-size: 11px; padding: 0px 8px 0px 8px; border-collapse:separate;">
|
||||
<tr><td valign="middle" align="left">
|
||||
${user.company_id.name}
|
||||
</td></tr>
|
||||
<tr><td valign="middle" align="left" style="opacity: 0.7;">
|
||||
${user.company_id.phone}
|
||||
% if user.company_id.phone and (user.company_id.email or user.company_id.website)
|
||||
|
|
||||
% endif
|
||||
% if user.company_id.email
|
||||
<a href="'mailto:%s' % ${user.company_id.email}" style="text-decoration:none; color: #454748;">${user.company_id.email}</a>
|
||||
% endif
|
||||
% if user.company_id.email and user.company_id.website
|
||||
|
|
||||
% endif
|
||||
% if user.company_id.website
|
||||
<a href="'%s' % ${user.company_id.website}" style="text-decoration:none; color: #454748;">
|
||||
${user.company_id.website}
|
||||
</a>
|
||||
% endif
|
||||
</td></tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td></tr>
|
||||
<!-- POWERED BY -->
|
||||
<tr><td align="center" style="min-width: 590px;">
|
||||
<table border="0" cellpadding="0" cellspacing="0" width="590" style="min-width: 590px; background-color: #F1F1F1; color: #454748; padding: 8px; border-collapse:separate;">
|
||||
<tr><td style="text-align: center; font-size: 13px;">
|
||||
Powered by <a target="_blank" href="https://www.odoo.com" style="color: #875A7B;">Odoo</a>
|
||||
</td></tr>
|
||||
</table>
|
||||
</td></tr>
|
||||
</table>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -207,13 +207,82 @@ class LunchOrderLine(models.Model):
|
||||
line.with_context(lunch_date=line.order_id.date)._check_supplier_availibility()
|
||||
return res
|
||||
|
||||
@api.one
|
||||
def order(self):
|
||||
"""
|
||||
The order_line is ordered to the vendor but isn't received yet
|
||||
"""
|
||||
if self.user_has_groups("lunch.group_lunch_manager"):
|
||||
self.state = 'ordered'
|
||||
self.write({'state': 'ordered'})
|
||||
|
||||
order = {
|
||||
'supplier': False,
|
||||
'company': False,
|
||||
'currency': False,
|
||||
}
|
||||
group_lines = {}
|
||||
for line in self:
|
||||
if not line.supplier:
|
||||
# do not send emails for products with no suppliers
|
||||
continue
|
||||
|
||||
if order['supplier'] and line.supplier != order['supplier']:
|
||||
raise ValidationError(_("Validate order for one supplier at a time to send emails (mixed orders from %s and %s)") % (
|
||||
order['supplier'].display_name, line.supplier.display_name))
|
||||
order['supplier'] = line.supplier
|
||||
|
||||
if order['company'] and line.order_id.company_id != order['company']:
|
||||
raise ValidationError(_("Validate order for one company at a time to send emails (mixed orders from %s and %s)") % (
|
||||
order['company'].name, line.order_id.company_id.name))
|
||||
order['company'] = line.order_id.company_id
|
||||
|
||||
if order['currency'] and line.currency_id != order['currency']:
|
||||
raise ValidationError(_("Validate order for one currency at a time to send emails (mixed orders from %s and %s)") % (
|
||||
order['currency'].name, line.currency_id.name))
|
||||
order['currency'] = line.currency_id
|
||||
|
||||
# group the order by products and note
|
||||
key = (line.product_id, line.note)
|
||||
group_lines.setdefault(key, 0)
|
||||
group_lines[key] += 1
|
||||
|
||||
order['company_name'] = order['company'].name
|
||||
order['currency_id'] = order['currency'].id
|
||||
order['supplier_id'] = order['supplier'].id
|
||||
order['supplier_name'] = order['supplier'].name
|
||||
order['supplier_email'] = order['supplier'].email_formatted
|
||||
|
||||
lines = []
|
||||
# sort by product name, note
|
||||
for product, note in sorted(group_lines, key=lambda k: (k[0].name, bool(k[1]))):
|
||||
quantity = group_lines[(product, note)]
|
||||
lines.append({
|
||||
'product': product.name,
|
||||
'note': note or '',
|
||||
'quantity': quantity,
|
||||
'price': product.price * quantity,
|
||||
})
|
||||
|
||||
order['amount_total'] = sum(l['price'] for l in lines)
|
||||
|
||||
template = self.env.ref('lunch.lunch_order_mail_supplier', raise_if_not_found=False)
|
||||
ctx = dict(
|
||||
default_composition_mode='comment',
|
||||
default_model='lunch.order',
|
||||
default_use_template=bool(template),
|
||||
default_template_id=template.id,
|
||||
default_lang=order['supplier'].lang or self.env.user.lang,
|
||||
order=order,
|
||||
lines=lines,
|
||||
)
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'mail.compose.message',
|
||||
'target': 'new',
|
||||
'context': ctx,
|
||||
}
|
||||
|
||||
else:
|
||||
raise AccessError(_("Only your lunch manager processes the orders."))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user