Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tko_coexiste_br_account/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ def write(self, vals):
due_date = datetime.datetime.strptime(due_date, OE_DFORMAT).date()
for move_line in record.move_id.line_ids:
move_line.date_maturity = due_date
super(AccountInvoice, record).write(vals)
record.draft_invoice_validate()
return super(AccountInvoice, self).write(vals)
return True


class AccountInvoiceLine(models.Model):
Expand Down
26 changes: 26 additions & 0 deletions tko_purchase_requisition/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# ThinkOpen Solutions Brasil
# Copyright (C) Thinkopen Solutions <http://www.tkobr.com>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import purchase_requisition
import wizard
50 changes: 50 additions & 0 deletions tko_purchase_requisition/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# ThinkOpen Solutions Brasil
# Copyright (C) Thinkopen Solutions <http://www.tkobr.com>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

{
'name': 'Merge Purchase Requisition Orders',
'version': '10.0.0.0.0',
'category': 'Customizations',
'sequence': 14,
'complexity': 'medium',
'description': ''' == This module allows to merge Requisition Orders in Draft Stage ==\n
''',
'author': 'ThinkOpen Solutions Brasil',
'website': 'http://www.tkobr.com',
'depends': [
'purchase_requisition',
],
'data': [
'purchase_requisition_view.xml',
'wizard/purchase_requisition_wizard_view.xml',
],
'init': [],
'demo': [],
'update': [],
'test': [], # YAML files with tests
'installable': True,
'application': False,
'auto_install': False,
'certificate': '',
}
62 changes: 62 additions & 0 deletions tko_purchase_requisition/purchase_requisition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# ThinkOpen Solutions Brasil
# Copyright (C) Thinkopen Solutions <http://www.tkobr.com>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from odoo import models, fields, api


class PurchaseRequisition(models.Model):
_inherit = 'purchase.requisition'

parent_id = fields.Many2one('purchase.requisition', string='Merged Into', readonly=True)
child_ids = fields.One2many('purchase.requisition','parent_id','Children')


@api.multi
def send_mail_to_all_quotations(self):
template_id = self.env.ref('purchase.email_template_edi_purchase')
if template_id:
for rfq in self.purchase_ids:
if rfq.partner_id.email:
values = template_id.generate_email(rfq.id)
values['email_to'] = rfq.partner_id.email
values['email_from'] = self.env.user.email
mail = self.env['mail.mail'].create(values)
attachment_ids = []
# create attachments
for attachment in values['attachments']:
attachment_data = {
'name': attachment[0],
'datas_fname': attachment[0],
'datas': attachment[1],
'res_model': 'mail.message',
'res_id': mail.mail_message_id.id,
}
attachment_ids.append(self.env['ir.attachment'].create(attachment_data).id)
if attachment_ids:
mail.write({'attachment_ids': [(6, 0, attachment_ids)]})
# send mail
mail.send()
# change status of RFQ
rfq.state = 'sent'
return True
33 changes: 33 additions & 0 deletions tko_purchase_requisition/purchase_requisition_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<openerp>
<data>
<record id="purchase_requisition_form_inherit" model="ir.ui.view">
<field name="name">purchase.requisition</field>
<field name="model">purchase.requisition</field>
<field name="inherit_id" ref="purchase_requisition.view_purchase_requisition_form"/>
<field name="arch" type="xml">
<field name="picking_type_id" position="after">
<field name="parent_id" attrs="{'invisible': [('parent_id','=',False)]}"/>
</field>
<xpath expr="//form/sheet/div[@name='button_box']/button[@class='oe_stat_button']" position="before">
<button name="send_mail_to_all_quotations" type="object" string="Send Mail to All"
attrs="{'invisible': ['|', ('purchase_ids','=',[]),('state', 'in', ('draft' ,'open','done'))]}"
class="btn-primary" style="margin-right: 10px;"/>
</xpath>
<notebook position="inside">
<page name="child_ids" string="Origin" attrs="{'invisible':[('child_ids','=',[])]}">
<field name="child_ids" nolabel="1" readonly="1">
<tree>
<field name="name"/>
<field name="origin"/>
<field name="state"/>
</tree>
</field>
</page>
<page name="purchase_ids" string="Purchase" invisible="1">
<field name="purchase_ids"/>
</page>
</notebook>
</field>
</record>
</data>
</openerp>
25 changes: 25 additions & 0 deletions tko_purchase_requisition/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# ThinkOpen Solutions Brasil
# Copyright (C) Thinkopen Solutions <http://www.tkobr.com>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import purchase_requisition_wizard
87 changes: 87 additions & 0 deletions tko_purchase_requisition/wizard/purchase_requisition_wizard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# ThinkOpen Solutions Brasil
# Copyright (C) Thinkopen Solutions <http://www.tkobr.com>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import fields, models, api
from openerp.exceptions import Warning


class PurchaseRequisitionWizard(models.TransientModel):
_name = 'purchase.requisition.wizard'

requisition_order_ids = fields.Many2many('purchase.requisition', 'requisition_order_merge_wizard_rel', 'wizard_id',
'requisition_id', string='Requisition Orders')

@api.model
def default_get(self, fields):
res = super(PurchaseRequisitionWizard, self).default_get(fields)
active_ids = self.env.context.get('active_ids', [])
if active_ids:
res['requisition_order_ids'] = [(6, 0, active_ids)]
return res

@api.multi
def validate_requisition_orders(self):
invalid_orders = []
for order in self.requisition_order_ids:
if order.state != 'draft':
invalid_orders.append(order.name)
return invalid_orders

@api.multi
def merge_requisition_orders(self):
self.ensure_one()
invalid_orders = self.validate_requisition_orders()
if len(invalid_orders):
raise Warning("%s orders not in Draft stage" % invalid_orders)
requisition_line_vals = {}
for order in self.requisition_order_ids:
for line in order.line_ids:
uom_id = line.product_uom_id.id or False
if line.product_id.id not in requisition_line_vals.keys():
requisition_line_vals.update({line.product_id.id: (line.product_qty, uom_id)})
else:
requisition_line_vals[line.product_id.id] = (requisition_line_vals[
line.product_id.id][0] + line.product_qty, uom_id)
# create requisition_order
order = self.requisition_order_ids[0].sudo().copy(default={'line_ids': False})
for product_id, qty_uom in requisition_line_vals.iteritems():
self.env['purchase.requisition.line'].create(
{'product_id': product_id, 'product_qty': qty_uom[0], 'requisition_id': order.id,
'product_uom_id': qty_uom[1]})
# cancel selected orders
self.requisition_order_ids.write({'parent_id': order.id})
# cancel orders
for tender in self.requisition_order_ids:
tender.action_cancel()
model, view_id = self.env['ir.model.data'].get_object_reference('purchase_requisition',
'view_purchase_requisition_form')
# return target form
return {
'view_type': 'form',
'view_mode': 'form',
'view_id': view_id,
'type': 'ir.actions.act_window',
'res_model': 'purchase.requisition',
'res_id': order.id,
'view_type': 'form',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<openerp>
<data>
<record id="purchase_requisition_wizard_form" model="ir.ui.view">
<field name="name">purchase.requisition.wizard</field>
<field name="model">purchase.requisition.wizard</field>
<field name="arch" type="xml">
<form string="Merge Requisition Orders" version="7.0">
<group string="Requisition Orders">
<field name="requisition_order_ids" domain="[('state','=','draft')]" widget="many2many_tags" nolabel="1" options="{'no_create': True}"/>
</group>
<footer>
<button name="merge_requisition_orders"
string="Merge" type="object"
class="oe_highlight"
/>
<button string="Cancelar" special="cancel"/>
</footer>
</form>
</field>
</record>


<act_window name="Merge Requisition Orders"
res_model="purchase.requisition.wizard"
src_model="purchase.requisition"
view_mode="form"
target="new"
key2="client_action_multi"
id="purchase_requisition_wizard_action"/>


</data>
</openerp>