Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modulo sale_order_merge para Ross #431

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
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
1 change: 1 addition & 0 deletions sale_order_merge/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions sale_order_merge/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
'name': "Junção de orçamentos em um único pedido",
'summary': """Permite juntar pedidos de venda""",
'description': """Permite juntar pedidos de venda""",
"author": "Trust-Code",
"license": "LGPL-3",
'category': 'Sales',
'version': '14.0',
'depends': [
'sale',
],
'data': [
"views/sale_order.xml",
]
}
1 change: 1 addition & 0 deletions sale_order_merge/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
21 changes: 21 additions & 0 deletions sale_order_merge/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from odoo import api, fields, models
from odoo.exceptions import UserError


class SaleOrder(models.Model):
_inherit = 'sale.order'

def merge_and_confirm_sale_order(self):
orders = self.filtered(lambda x: x.state in ('draft', 'sent'))
partners = orders.mapped('partner_id.commercial_partner_id')
if len(partners) > 1:
raise UserError('Apenas orçamentos para a mesma empresa podem ser confirmados')

new_order = orders[0].copy({'order_line': []})

for order in orders:
for line in order.order_line:
line.copy({'order_id': new_order.id})
order.action_cancel()

new_order.action_confirm()
15 changes: 15 additions & 0 deletions sale_order_merge/views/sale_order.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<odoo>

<record id="hr_expense_submit_action_server" model="ir.actions.server">
<field name="name">Confirmar orçamentos</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="binding_model_id" ref="sale.model_sale_order"/>
<field name="state">code</field>
<field name="code">
if records:
action = records.merge_and_confirm_sale_order()
</field>
</record>

</odoo>