Skip to content
Merged
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
31 changes: 31 additions & 0 deletions kk_sites/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@
import json
import requests
from unicodedata import normalize
from odoo.exceptions import UserError


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

def _prepare_invoice(self):
lines = self.order_line.filtered(
lambda x: x.invoice_status != 'invoiced')
if all(not (line.is_invoice_ok and line.purchase_order) for line in
lines):
raise UserError('Não é possível faturar a ordem %s pois nenhuma das\
linhas faturáveis está liberada para faturamento e ou a\
ordem de compra não está preenchida.\n\
Acesse as linhas que deseja faturar, marque a opção "Liberar\
para faturamento" e preencha o campo "Ordem de compra"'
% self.name)
else:
return super(SaleOrder, self)._prepare_invoice()


class SaleOrderLine(models.Model):
Expand All @@ -18,6 +37,18 @@ class SaleOrderLine(models.Model):

description_proposta = fields.Html(string="Descrição para proposta")

is_invoice_ok = fields.Boolean('Liberar para Faturamento')

purchase_order = fields.Char('Ordem de Compra')

def invoice_line_create(self, invoice_id, qty):
lines = super(SaleOrderLine, self).invoice_line_create(invoice_id, qty)
for line in lines:
if any(not (item.is_invoice_ok and item.purchase_order) for item
in line.sale_line_ids):
line.unlink()
return lines

def get_next_folder_number(self, project):
link = project.kk_site_id.pasta_servidor
res = self.env['kk.sites'].get_server_folders(link, False)
Expand Down
39 changes: 38 additions & 1 deletion kk_sites/views/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,43 @@
<label for="description_proposta" />
<field name="description_proposta" type="html" nolabel="1" />
</xpath>
<xpath expr="//field[@name='order_line']/form/group/group[2]" position="inside">
<field name="purchase_order" />
<field name="is_invoice_ok" />
</xpath>
</field>
</record>
</odoo>
<record id="sale_order_kk_site_tree" model="ir.ui.view">
<field name="name">sale.order.kk.site.tree</field>
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.view_order_line_tree" />
<field name="arch" type="xml">
<tree position="replace">
<tree string="Linhas dos Pedidos" editable="top" >
<field name="order_id" readonly="1" />
<field name="order_partner_id" readonly="1" />
<field name="name" readonly="1" />
<field name="purchase_order" />
<field name="is_invoice_ok" />
<field name="salesman_id" readonly="1" invisible="1" />
<field name="product_uom_qty" string="Qty" readonly="1"/>
<field name="qty_delivered" readonly="1"/>
<field name="qty_invoiced" readonly="1"/>
<field name="qty_to_invoice" readonly="1" invisible="1"/>
<field name="product_uom" string="Unit of Measure" groups="product.group_uom" readonly="1" invisible="1" />
<field name="price_subtotal" sum="Total" widget="monetary" readonly="1"/>
</tree>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_show_sale_line_tree">
<field name="name">Linhas dos Pedidos</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order.line</field>
<field name="view_type">form</field>
<field name="view_mode">tree</field>
</record>

<menuitem parent="sale.menu_sale_invoicing" id="menu_linha_vendas" action="action_show_sale_line_tree" sequence="10" />

</odoo>