Skip to content

Commit

Permalink
Merge pull request OCA#33 from leemannd/bsrtl159
Browse files Browse the repository at this point in the history
[WIP] bsrtl159 - Ghost Product & new state on SO
  • Loading branch information
gurneyalex authored Mar 17, 2017
2 parents c117781 + dd6bc67 commit 2eee944
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 6 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ latest (unreleased)
**Features and Improvements**

* Add a second user on CRM leads
* Ghosts products and indicative sales quotes: have placeholder products on
sale orders, and have an intermediate state on sales quotations.

**Bugfixes**

Expand Down
6 changes: 5 additions & 1 deletion odoo/local-src/specific_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"website": "http://www.camptocamp.com",
"license": "GPL-3 or any later version",
"category": "Sale",
"data": ['views/sale_order_crm.xml'],
"data": [
'views/product_views.xml',
'views/sale_order_crm.xml',
'data/res_groups_data.xml',
],
'installable': True,
}
17 changes: 17 additions & 0 deletions odoo/local-src/specific_sale/data/res_groups_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo noupdate="1">

<record id="rtl_eng_validation" model="res.groups">
<field name="name">Roctool Engineering Managers</field>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<record id="rtl_sys_manager" model="res.groups">
<field name="name">Roctool Process Managers</field>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>
<record id="rtl_pro_manager" model="res.groups">
<field name="name">Roctool System Managers</field>
<field name="users" eval="[(4, ref('base.user_root'))]"/>
</record>

</odoo>
4 changes: 3 additions & 1 deletion odoo/local-src/specific_sale/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import sale_order
from . import product
from . import sale_order
from . import mail_compose_message
76 changes: 76 additions & 0 deletions odoo/local-src/specific_sale/models/mail_compose_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
# Author: Denis Leemann
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, api


class MailComposeMessage(models.TransientModel):
_inherit = 'mail.compose.message'

@api.multi
def onchange_template_id(self,
template_id,
composition_mode,
model,
res_id):
values = super(MailComposeMessage, self).onchange_template_id(
template_id, composition_mode, model, res_id
)

if model != 'sale.order':
return values

order = self.env['sale.order'].browse(res_id)
if not order.sales_condition:
return values

# xmlids of email.template in which we join the sales condition
# document
sale_condition_xmlids = (
'sale.email_template_edi_sale',
)
condition_template_ids = []
for xmlid in sale_condition_xmlids:
template = self.env.ref(xmlid, raise_if_not_found=False)
condition_template_ids.append(template.id)

# sending a mail quote
if template_id not in condition_template_ids:
return values

attachment = self.env['ir.attachment'].search(
[('res_model', '=', 'sale.order'),
('res_field', '=', 'sales_condition'),
('res_id', '=', order.id),
],
limit=1,
)
fname = order.sales_condition_filename
# Replicate what's done in
# addons/mail_template/wizard/mail_compose_message.py
# The attachment should be cleaned by odoo later
data_attach = {
'name': fname,
'datas': attachment.datas,
'datas_fname': fname,
'res_model': 'mail.compose.message',
'res_id': 0,
'type': 'binary',
}
new_attachment = self.env['ir.attachment'].create(data_attach)
value = values['value']
if 'attachment_ids' in value:
# add the new attachment to the existing command created
# by the super onchange
for cmd in value['attachment_ids']:
if cmd[0] == 6:
ids = cmd[2]
ids.append(new_attachment.id)
else:
raise Exception('unhandled')
else:
value['attachment_id'] = [(6, 0, new_attachment.ids)]

return values
14 changes: 14 additions & 0 deletions odoo/local-src/specific_sale/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# Author: Denis Leemann
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, fields


class ProductTemplate(models.Model):
_inherit = 'product.template'

is_ghost = fields.Boolean(
string='Ghost Product',
)
101 changes: 98 additions & 3 deletions odoo/local-src/specific_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, fields, api
from odoo import models, fields, api, _
from odoo.exceptions import UserError


class SaleOrder(models.Model):
Expand All @@ -16,9 +17,49 @@ class SaleOrder(models.Model):
project_market_id = fields.Many2one(comodel_name='project.market',
required=True)

engineering_validation_id = fields.Many2one(
'res.users',
string='Engineering Validation',
track_visibility=True,
copy=False,
readonly=True,
)
system_validation_id = fields.Many2one(
'res.users',
string='System Validation',
track_visibility=True,
copy=False,
readonly=True,
)
process_validation_id = fields.Many2one(
'res.users',
string='Process Validation',
track_visibility=True,
copy=False,
readonly=True,
)
sales_condition = fields.Binary(
string='Sales Condition',
required=True,
attachment=True,
states={'draft': [('required', False)]}
)
sales_condition_filename = fields.Char()

@api.model
def _setup_fields(self, partial):
super(SaleOrder, self)._setup_fields(partial)
new_selection = []
for state, name in self._fields['state'].selection:
new_selection.append((state, name))
if state == 'draft':
new_selection.append(('final_quote', _('Final Quote')))
self._fields['state'].selection = new_selection

def _generate_acc_name(self, use_existing_one=None):
"""
generate an analytic account name according to the following structure:
""" Generate analytic account name
According to the following structure:
123ABCXXYYZZ with
123: number autoincrement (use Odoo sequence)
ABC: customer.ref field
Expand Down Expand Up @@ -79,3 +120,57 @@ def onchange_order_line(self):
}
option_lines.append((0, 0, data))
self.options = option_lines

@api.multi
def _check_ghost(self):
for so in self:
ghost_prd = self.order_line.search_read(
[('product_id.is_ghost', '=', True),
('order_id', '=', self.id)])
# ghost_prd allowed only on draft
if ghost_prd:
raise UserError(_(
'Ghost product is allowed only on draft Sale Orders.'))

@api.multi
def _check_sales_condition(self):
for so in self:
if not self.sales_condition:
raise UserError(_(
'You need to attach Sales Condition.'))

@api.multi
def _check_validators(self):
if not (self.engineering_validation_id and
self.system_validation_id and
self.process_validation_id):
raise UserError(_('The Sale Order needs to be reviewed.'))

def write(self, vals):
# from ' draft you can switch only to 'final_quote'
if (self.state == 'draft' and
vals.get('state', 'final_quote') != 'final_quote'):
raise UserError(
'A Draft Sale Order can only step to "final_quote" ')
if vals.get('state', 'draft') != 'draft':
self._check_ghost()
self._check_sales_condition()
self._check_validators()
return super(SaleOrder, self).write(vals)

def action_validate_eng(self):
self.engineering_validation_id = self.env.context['uid']

def action_validate_sys(self):
self.system_validation_id = self.env.context['uid']

def action_validate_pro(self):
self.process_validation_id = self.env.context['uid']

@api.multi
def action_confirm(self):
for order in self:
if order.state == 'draft':
order.state = 'final_quote'
else:
order.action_confirm()
32 changes: 32 additions & 0 deletions odoo/local-src/specific_sale/views/product_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="view_template_property_form" model="ir.ui.view">
<field name="name">product.ghost</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<div name="options" position="inside">
<div>
<field name="is_ghost"/>
<label for="is_ghost"/>
</div>
</div>
</field>
</record>

<record id="product_template_only_form_view" model="ir.ui.view">
<field name="name">product.template.ghost.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<div name="options" position="inside">
<div>
<field name="is_ghost"/>
<label for="is_ghost"/>
</div>
</div>
</field>
</record>

</odoo>
34 changes: 33 additions & 1 deletion odoo/local-src/specific_sale/views/sale_order_crm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,48 @@
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">


<header position="inside">
<!-- validation Buttons -->
<button name="action_validate_eng"
context="{'validator': 'eng'}"
string="Engineering Validation"
class="btn-primary"
groups="specific_sale.rtl_eng_validation"
type="object"/>

<button name="action_validate_sys"
string="System Validation"
class="btn-primary"
groups="specific_sale.rtl_sys_manager"
type="object"/>

<button name="action_validate_pro"
string="Process Validation"
class="btn-primary"
groups="specific_sale.rtl_pro_manager"
type="object"/>
</header>

<xpath expr="//field[@widget='statusbar']" position="replace">
<field name="state" widget="statusbar" statusbar_visible="draft,final_quote,sent,sale"/>
</xpath>

<notebook position="inside">
<page string="RocTool" name="roctool">
<group name="project_name_computation" string="Project configuration">
<field name="project_zone_id"/>
<field name="project_process_id"/>
<field name="project_market_id"/>
<field name='sales_condition' filename="sales_condition_filename"/>
<field name='sales_condition_filename' invisible="1"/>
<field name='engineering_validation_id'/>
<field name='system_validation_id'/>
<field name='process_validation_id'/>
</group>

</page>
</notebook>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions odoo/migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ migration:
addons:
upgrade:
- specific_crm
- specific_sale

0 comments on commit 2eee944

Please sign in to comment.