add sale detailed report and force draft wizard
This commit is contained in:
parent
edd4d53c75
commit
a4fefaa545
|
@ -9,7 +9,6 @@ import configuration
|
|||
import stock
|
||||
import invoice
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
configuration.Configuration,
|
||||
|
@ -22,11 +21,15 @@ def register():
|
|||
stock.ShipmentOutReturn,
|
||||
sale.SaleBySupplierStart,
|
||||
sale.SaleLine,
|
||||
sale.SaleShopDetailedStart,
|
||||
invoice.Invoice,
|
||||
module='sale_shop', type_='model')
|
||||
Pool.register(
|
||||
sale.PrintSaleBySupplier,
|
||||
sale.SaleShopDetailed,
|
||||
sale.SaleShopForceDraft,
|
||||
module='sale_shop', type_='wizard')
|
||||
Pool.register(
|
||||
sale.SaleBySupplier,
|
||||
sale.SaleShopDetailedReport,
|
||||
module='sale_shop', type_='report')
|
||||
|
|
362
locale/es.po
362
locale/es.po
|
@ -30,6 +30,10 @@ msgstr ""
|
|||
"No puede editar este pedido porque no dispone de permiso de edición en esta "
|
||||
"tienda."
|
||||
|
||||
msgctxt "error:sale_shop.force_draft:"
|
||||
msgid "The electronic invoice already exist!"
|
||||
msgstr "La factura electronica ya existe!"
|
||||
|
||||
msgctxt "field:account.invoice,authorization:"
|
||||
msgid "Authorization"
|
||||
msgstr "Autorización"
|
||||
|
@ -190,7 +194,6 @@ msgctxt "field:sale.shop.company_employee,create_date:"
|
|||
msgid "Create Date"
|
||||
msgstr "Fecha de Creación"
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "field:sale.shop.company_employee,create_uid:"
|
||||
msgid "Create User"
|
||||
msgstr "Usuario de creción"
|
||||
|
@ -239,6 +242,38 @@ msgctxt "field:sale_shop.sale_by_supplier.start,supplier:"
|
|||
msgid "Supplier"
|
||||
msgstr "Proveedor"
|
||||
|
||||
msgctxt "field:sale_shop.sale_detailed.start,company:"
|
||||
msgid "Company"
|
||||
msgstr "Empresa"
|
||||
|
||||
msgctxt "field:sale_shop.sale_detailed.start,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Fin"
|
||||
|
||||
msgctxt "field:sale_shop.sale_detailed.start,id:"
|
||||
msgid "ID"
|
||||
msgstr "UP"
|
||||
|
||||
msgctxt "field:sale_shop.sale_detailed.start,party:"
|
||||
msgid "Party"
|
||||
msgstr "Terceros"
|
||||
|
||||
msgctxt "field:sale_shop.sale_detailed.start,product:"
|
||||
msgid "Product"
|
||||
msgstr "Productos"
|
||||
|
||||
msgctxt "field:sale_shop.sale_detailed.start,salesman:"
|
||||
msgid "Salesman"
|
||||
msgstr "Vendedor"
|
||||
|
||||
msgctxt "field:sale_shop.sale_detailed.start,shop:"
|
||||
msgid "Shop"
|
||||
msgstr "Tienda"
|
||||
|
||||
msgctxt "field:sale_shop.sale_detailed.start,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Inicio"
|
||||
|
||||
msgctxt "field:stock.shipment.out,shop_addresses:"
|
||||
msgid "Shop Addresses"
|
||||
msgstr "Direcciones de la Tienda"
|
||||
|
@ -251,6 +286,10 @@ msgctxt "model:ir.action,name:"
|
|||
msgid "Zones"
|
||||
msgstr "Zonas"
|
||||
|
||||
msgctxt "model:ir.action,name:act_sale_shop_force_draft"
|
||||
msgid "Sale Shop Force Draft"
|
||||
msgstr "Forzar a Borrador"
|
||||
|
||||
msgctxt "model:ir.action,name:act_sale_shop_form"
|
||||
msgid "Shops"
|
||||
msgstr "Tiendas"
|
||||
|
@ -259,10 +298,18 @@ msgctxt "model:ir.action,name:report_sale_by_supplier"
|
|||
msgid "Report Sale By Supplier"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "model:ir.action,name:report_sale_shop_detailed"
|
||||
msgid "Sale Shop Detailed"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "model:ir.action,name:wizard_print_sale_by_supplier"
|
||||
msgid "Sale By Supplier"
|
||||
msgstr "Reporte Ventas Por Proveedor"
|
||||
|
||||
msgctxt "model:ir.action,name:wizard_print_sale_shop_detailed"
|
||||
msgid "Print Sale Shop Detailed"
|
||||
msgstr "Venta Detallada Por Tienda"
|
||||
|
||||
msgctxt "model:ir.ui.menu,name:"
|
||||
msgid "Zones"
|
||||
msgstr "Zonas"
|
||||
|
@ -275,6 +322,10 @@ msgctxt "model:ir.ui.menu,name:menu_sale_shop"
|
|||
msgid "Shops"
|
||||
msgstr "Tiendas"
|
||||
|
||||
msgctxt "model:ir.ui.menu,name:menu_sale_shop_detailed"
|
||||
msgid "Print Sale Shop Detailed"
|
||||
msgstr "Venta Detallada Por Tienda"
|
||||
|
||||
msgctxt "model:sale.shop,name:"
|
||||
msgid "Sale Shop"
|
||||
msgstr "Tienda"
|
||||
|
@ -291,6 +342,307 @@ msgctxt "model:sale_shop.sale_by_supplier.start,name:"
|
|||
msgid "Sale By Supplier Start"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "model:sale_shop.sale_detailed.start,name:"
|
||||
msgid "Sale Shop Detailed Start"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "$"
|
||||
msgstr "$"
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "%"
|
||||
msgstr "%"
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "("
|
||||
msgstr "("
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "(line.product.cost_price * line.quantity)"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid ")"
|
||||
msgstr ")"
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid ","
|
||||
msgstr ","
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "-"
|
||||
msgstr "-"
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "/"
|
||||
msgstr "/"
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "/for"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "/if"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "00/00/0000"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "00:00:00"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "???"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "BASE"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "CANT"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "CATEGORÍA"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "CLIENTE"
|
||||
msgstr "CLIENTE"
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "CON IVA"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "COSTO TOTAL SIN IVA"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "COSTO UNITARIO"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "DE VENTAS DETALLADAS"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "DESCRIPTION"
|
||||
msgstr "DESCRIPCION"
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "ESTADO FACTURA"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "ESTADO VENTA"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "FECHA FACTURA"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "FECHA FINAL"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "FECHA INICIAL"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "FECHA PEDIDO"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "FORMA DE PAGO"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "NOTAS"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "NÚMERO FACTURA"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "NÚMERO VENTA"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "PEDIDO"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "PRECIO UNIT"
|
||||
msgstr ""
|
||||
|
||||
#, fuzzy
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "PRODUCTO"
|
||||
msgstr "Producto"
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "Página"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "REPORTE"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "SIN IVA"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "SUBTOTAL"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "TIENDA"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "TOTAL"
|
||||
msgstr "TOTAL"
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "TRYTON ERP"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "UDM"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "VENDEDOR"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "amount"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "amount_w_tax"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "data['end_date']"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "data['start_date']"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "de"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "for each='line in records'"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "if test=\"line.type == 'line'\""
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.amount"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.amount_w_tax"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.cost_price"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.cost_price_with_tax"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.product.account_category and line.product.account_category.name"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.product.description"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.product.rec_name"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.quantity"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.comment"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.invoice and line.sale.invoice.invoice_date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.invoice.state_string"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.invoices and line.sale.invoices[0].number"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.number"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.party.name"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.payment_term and line.sale.payment_term.name"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.position"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.sale_date"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.salesman and line.sale.salesman.party.name"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.shop and line.sale.shop.name"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.sale.state_string"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.unit.symbol"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "line.unit_price"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.report_sale_detailed:"
|
||||
msgid "€"
|
||||
msgstr ""
|
||||
|
||||
msgctxt "report:sale_shop.sale_by_supplier_report:"
|
||||
msgid "$"
|
||||
msgstr "$"
|
||||
|
@ -470,3 +822,11 @@ msgstr "Cancelar"
|
|||
msgctxt "wizard_button:sale_shop.print_sale_by_supplier,start,print_:"
|
||||
msgid "Print"
|
||||
msgstr "Imprimir"
|
||||
|
||||
msgctxt "wizard_button:sale_shop.sale_detailed,start,end:"
|
||||
msgid "Cancel"
|
||||
msgstr "Cancelar"
|
||||
|
||||
msgctxt "wizard_button:sale_shop.sale_detailed,start,print_:"
|
||||
msgid "Print"
|
||||
msgstr "Imprimir"
|
||||
|
|
211
sale.py
211
sale.py
|
@ -9,8 +9,10 @@ from trytond.transaction import Transaction
|
|||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Bool, Eval, Or
|
||||
import logging
|
||||
from sql import Table
|
||||
from trytond.report import Report
|
||||
from trytond.wizard import Wizard, StateView, StateReport, Button
|
||||
from trytond.wizard import (
|
||||
Wizard, StateView, StateAction, StateReport, StateTransition, Button)
|
||||
|
||||
__all__ = ['Sale', 'SaleBySupplierStart', 'SaleBySupplier',
|
||||
'PrintSaleBySupplier', 'SaleLine']
|
||||
|
@ -357,3 +359,210 @@ class Sale(metaclass=PoolMeta):
|
|||
invoice.comment = self.comment
|
||||
invoice.shop = self.shop.id
|
||||
return invoice
|
||||
|
||||
|
||||
class SaleShopDetailedStart(ModelView):
|
||||
'Sale Shop Detailed Start'
|
||||
__name__ = 'sale_shop.sale_detailed.start'
|
||||
start_date = fields.Date('Start Date', required=True)
|
||||
end_date = fields.Date('End Date', required=True)
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
salesman = fields.Many2One('company.employee', 'Salesman')
|
||||
party = fields.Many2One('party.party', 'Party')
|
||||
product = fields.Many2One('product.product', 'Product')
|
||||
shop = fields.Many2One('sale.shop', 'Shop')
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
|
||||
class SaleShopDetailed(Wizard):
|
||||
'Sale Shop Detailed'
|
||||
__name__ = 'sale_shop.sale_detailed'
|
||||
start = StateView('sale_shop.sale_detailed.start',
|
||||
'sale_shop.sale_shop_detailed_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Print', 'print_', 'tryton-ok', default=True),
|
||||
])
|
||||
print_ = StateAction('sale_shop.report_sale_detailed')
|
||||
|
||||
def do_print_(self, action):
|
||||
salesman_id = None
|
||||
party_id = None
|
||||
product_id = None
|
||||
shop_id = None
|
||||
if self.start.salesman:
|
||||
salesman_id = self.start.salesman.id
|
||||
if self.start.shop:
|
||||
shop_id = self.start.shop.id
|
||||
if self.start.party:
|
||||
party_id = self.start.party.id
|
||||
if self.start.product:
|
||||
product_id = self.start.product.id
|
||||
data = {
|
||||
'company': self.start.company.id,
|
||||
'start_date': self.start.start_date,
|
||||
'end_date': self.start.end_date,
|
||||
'salesman': salesman_id,
|
||||
'party': party_id,
|
||||
'product': product_id,
|
||||
'shop': shop_id,
|
||||
}
|
||||
return action, data
|
||||
|
||||
def transition_print_(self):
|
||||
return 'end'
|
||||
|
||||
|
||||
class SaleShopDetailedReport(Report):
|
||||
'Sale Shop Detailed Report'
|
||||
__name__ = 'sale_shop.report_sale_detailed'
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, records, data):
|
||||
report_context = super(SaleShopDetailedReport, cls).get_context(records, data)
|
||||
pool = Pool()
|
||||
|
||||
Sale = pool.get('sale.sale')
|
||||
SaleLine = pool.get('sale.line')
|
||||
Company = pool.get('company.company')
|
||||
|
||||
sales_line_dom = [
|
||||
('sale.sale_date', '>=', data['start_date']),
|
||||
('sale.sale_date', '<=', data['end_date']),
|
||||
('sale.company', '=', data['company']),
|
||||
('sale.state', 'in', ['processing', 'done']),
|
||||
]
|
||||
if data['salesman']:
|
||||
sales_line_dom.append(
|
||||
('sale.salesman', '=', data['salesman'])
|
||||
)
|
||||
if data['shop']:
|
||||
sales_line_dom.append(
|
||||
('sale.shop', '=', data['shop'])
|
||||
)
|
||||
if data['party']:
|
||||
sales_line_dom.append(
|
||||
('sale.party', '=', data['party'])
|
||||
)
|
||||
if data['product']:
|
||||
# lines = SaleLine.search([
|
||||
# ('product', '=', data['product'])
|
||||
# ])
|
||||
# line_ids = [l.id for l in lines]
|
||||
sales_line_dom.append(
|
||||
('product', '=', data['product'])
|
||||
)
|
||||
|
||||
start_lines = SaleLine.search(sales_line_dom, order=[('sale.sale_date', 'ASC')])
|
||||
lines = []
|
||||
amount = []
|
||||
amount_w_tax = []
|
||||
for line in start_lines:
|
||||
if line.type == 'line' and not line.product:
|
||||
Sale.raise_user_error('sale_not_product', line.sale.number)
|
||||
|
||||
is_invoiced = False
|
||||
if line.sale.invoices:
|
||||
for inv in line.sale.invoices:
|
||||
if inv.state not in ['draft', 'cancel']:
|
||||
is_invoiced = True
|
||||
if is_invoiced:
|
||||
lines.append(line)
|
||||
amount.append(line.amount)
|
||||
amount_w_tax.append(line.amount_w_tax)
|
||||
else:
|
||||
lines.append(line)
|
||||
amount.append(line.amount)
|
||||
amount_w_tax.append(line.amount_w_tax)
|
||||
|
||||
report_context['amount'] = sum(amount)
|
||||
report_context['amount_w_tax'] = sum(amount_w_tax)
|
||||
report_context['records'] = lines
|
||||
report_context['company'] = Company(data['company'])
|
||||
return report_context
|
||||
|
||||
|
||||
class SaleShopForceDraft(Wizard):
|
||||
'Sale Shop Force Draft'
|
||||
__name__ = 'sale_shop.force_draft'
|
||||
start_state = 'force_draft'
|
||||
force_draft = StateTransition()
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(SaleShopForceDraft, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'with_electronic_invoice': 'The electronic invoice already exist!',
|
||||
})
|
||||
|
||||
def transition_force_draft(self):
|
||||
sale_table = Table('sale_sale')
|
||||
invoice_table = Table('account_invoice')
|
||||
move_table = Table('account_move')
|
||||
stock_move_table = Table('stock_move')
|
||||
Sale = Pool().get('sale.sale')
|
||||
# Date = Pool().get('ir.date')
|
||||
|
||||
cursor = Transaction().connection.cursor()
|
||||
ids = Transaction().context['active_ids']
|
||||
if not ids:
|
||||
return 'end'
|
||||
sales = Sale.browse(ids)
|
||||
|
||||
for sale in sales:
|
||||
# if sale.sale_date != Date.today():
|
||||
# return 'end'
|
||||
|
||||
# The invoices must be delete
|
||||
for invoice in sale.invoices:
|
||||
if (hasattr(invoice, 'cufe') and invoice.cufe) or \
|
||||
hasattr(invoice, 'electronic_state') and \
|
||||
invoice.electronic_state == 'submitted':
|
||||
self.raise_user_error('with_electronic_invoice')
|
||||
if invoice.state == 'paid':
|
||||
self.unreconcile_move(invoice.move)
|
||||
if invoice.move:
|
||||
cursor.execute(*move_table.update(
|
||||
columns=[move_table.state],
|
||||
values=['draft'],
|
||||
where=move_table.id == invoice.move.id)
|
||||
)
|
||||
cursor.execute(*move_table.delete(
|
||||
where=move_table.id == invoice.move.id)
|
||||
)
|
||||
cursor.execute(*invoice_table.update(
|
||||
columns=[invoice_table.state, invoice_table.number],
|
||||
values=['validate', None],
|
||||
where=invoice_table.id == invoice.id)
|
||||
)
|
||||
cursor.execute(*invoice_table.delete(
|
||||
where=invoice_table.id == invoice.id)
|
||||
)
|
||||
|
||||
if sale.id:
|
||||
cursor.execute(*sale_table.update(
|
||||
columns=[sale_table.state],
|
||||
values=['draft'],
|
||||
where=sale_table.id == sale.id)
|
||||
)
|
||||
# The stock moves must be delete
|
||||
stock_moves = [m.id for line in sale.lines for m in line.moves]
|
||||
if stock_moves:
|
||||
cursor.execute(*stock_move_table.update(
|
||||
columns=[stock_move_table.state],
|
||||
values=['draft'],
|
||||
where=stock_move_table.id.in_(stock_moves)
|
||||
))
|
||||
|
||||
cursor.execute(*stock_move_table.delete(
|
||||
where=stock_move_table.id.in_(stock_moves))
|
||||
)
|
||||
return 'end'
|
||||
|
||||
def unreconcile_move(self, move):
|
||||
Reconciliation = Pool().get('account.move.reconciliation')
|
||||
reconciliations = [l.reconciliation for l in move.lines if l.reconciliation]
|
||||
if reconciliations:
|
||||
Reconciliation.delete(reconciliations)
|
||||
|
|
29
sale.xml
29
sale.xml
|
@ -54,5 +54,34 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
|
|||
pyson="1"/>
|
||||
<field name="rule_group" ref="rule_group_sale"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.report" id="report_sale_shop_detailed">
|
||||
<field name="name">Sale Shop Detailed</field>
|
||||
<field name="model"></field>
|
||||
<field name="report_name">sale_shop.report_sale_detailed</field>
|
||||
<field name="report">sale_shop/sale_detailed.ods</field>
|
||||
<field name="template_extension">ods</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="sale_shop_detailed_start_view_form">
|
||||
<field name="model">sale_shop.sale_detailed.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">sale_shop_detailed_start_form</field>
|
||||
</record>
|
||||
<record model="ir.action.wizard" id="wizard_print_sale_shop_detailed">
|
||||
<field name="name">Print Sale Shop Detailed</field>
|
||||
<field name="wiz_name">sale_shop.sale_detailed</field>
|
||||
</record>
|
||||
<menuitem parent="sale.menu_reporting" id="menu_sale_shop_detailed"
|
||||
action="wizard_print_sale_shop_detailed"/>
|
||||
|
||||
<record model="ir.action.wizard" id="act_sale_shop_force_draft">
|
||||
<field name="name">Sale Shop Force Draft</field>
|
||||
<field name="wiz_name">sale_shop.force_draft</field>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="action_sale_shop_force_draft_keyword">
|
||||
<field name="keyword">form_action</field>
|
||||
<field name="model">sale.sale,-1</field>
|
||||
<field name="action" ref="act_sale_shop_force_draft"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form cursor="start_date">
|
||||
<label name="salesman"/>
|
||||
<field name="salesman"/>
|
||||
<label name="company"/>
|
||||
<field name="company" widget="selection"/>
|
||||
<label name="start_date"/>
|
||||
<field name="start_date"/>
|
||||
<label name="end_date"/>
|
||||
<field name="end_date"/>
|
||||
<label name="party"/>
|
||||
<field name="party"/>
|
||||
<label name="product"/>
|
||||
<field name="product"/>
|
||||
<label name="shop"/>
|
||||
<field name="shop"/>
|
||||
</form>
|
Loading…
Reference in New Issue