add wizard for grouping invoices from purchase
This commit is contained in:
parent
9ee28308a7
commit
3efa6e17c3
|
@ -18,6 +18,7 @@ def register():
|
|||
purchase.PurchaseAnalyticStart,
|
||||
purchase.PurchasesDetailedStart,
|
||||
purchase.PurchaseUpdateStart,
|
||||
purchase.GroupingPurchasesStart,
|
||||
module='purchase_co', type_='model')
|
||||
Pool.register(
|
||||
account.PrintSupplierCertificate,
|
||||
|
@ -27,6 +28,7 @@ def register():
|
|||
purchase.PurchaseGenerateInvoice,
|
||||
purchase.PurchaseGenerateShipment,
|
||||
purchase.PurchaseUpdate,
|
||||
purchase.GroupingPurchases,
|
||||
module='purchase_co', type_='wizard')
|
||||
Pool.register(
|
||||
account.PrintSupplierCertificateReport,
|
||||
|
|
40
locale/es.po
40
locale/es.po
|
@ -1062,3 +1062,43 @@ msgstr "Cancelar"
|
|||
msgctxt "wizard_button:purchase_co.print_supplier_certificate,start,print_:"
|
||||
msgid "Ok"
|
||||
msgstr "Aceptar"
|
||||
|
||||
msgctxt "field:purchase.grouping_purchases.start,company:"
|
||||
msgid "Company"
|
||||
msgstr "Empresa"
|
||||
|
||||
msgctxt "field:purchase.grouping_purchases.start,currency:"
|
||||
msgid "Currency"
|
||||
msgstr "Moneda"
|
||||
|
||||
msgctxt "field:purchase.grouping_purchases.start,end_date:"
|
||||
msgid "End Date"
|
||||
msgstr "Fin"
|
||||
|
||||
msgctxt "field:purchase.grouping_purchases.start,start_date:"
|
||||
msgid "Start Date"
|
||||
msgstr "Inicio"
|
||||
|
||||
msgctxt "field:purchase.grouping_purchases.start,supplier:"
|
||||
msgid "Supplier"
|
||||
msgstr "Proveedor"
|
||||
|
||||
msgctxt "model:ir.ui.menu,name:menu_grouping_purchases"
|
||||
msgid "Create Invoice of Purchases"
|
||||
msgstr "Crear de Factura de Compras"
|
||||
|
||||
msgctxt "model:ir.action,name:wizard_create_grouping_purchases"
|
||||
msgid "Grouping Purchases"
|
||||
msgstr "Facturacion de Compras Agrupadas"
|
||||
|
||||
msgctxt "model:purchase.grouping_purchases.start,name:"
|
||||
msgid "Grouping Purchases Start"
|
||||
msgstr "Agrupación de Facturación Compras"
|
||||
|
||||
msgctxt "wizard_button:purchase.grouping_purchases,start,accept:"
|
||||
msgid "Ok"
|
||||
msgstr "Aceptar"
|
||||
|
||||
msgctxt "wizard_button:purchase.grouping_purchases,start,end:"
|
||||
msgid "Cancel"
|
||||
msgstr "Cancelar"
|
84
purchase.py
84
purchase.py
|
@ -1,5 +1,6 @@
|
|||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from itertools import chain
|
||||
from datetime import date, timedelta
|
||||
from decimal import Decimal
|
||||
from trytond.pyson import Eval, Not, Bool
|
||||
|
@ -677,3 +678,86 @@ class PurchaseUpdate(Wizard):
|
|||
('remove', [self.start.tax_remove.id])]})
|
||||
purchase.save()
|
||||
return 'end'
|
||||
|
||||
|
||||
class GroupingPurchasesStart(ModelView):
|
||||
'Grouping Purchases Start'
|
||||
__name__ = 'purchase.grouping_purchases.start'
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
supplier = fields.Many2One('party.party', 'Supplier', required=True)
|
||||
currency = fields.Many2One('currency.currency', 'Currency', required=True)
|
||||
start_date = fields.Date("Start Date", required=True)
|
||||
end_date = fields.Date("End Date", required=True)
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
|
||||
class GroupingPurchases(Wizard):
|
||||
'Grouping Purchases'
|
||||
__name__ = 'purchase.grouping_purchases'
|
||||
start = StateView(
|
||||
'purchase.grouping_purchases.start',
|
||||
'purchase_co.grouping_purchases_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Ok', 'accept', 'tryton-ok', default=True),
|
||||
])
|
||||
accept = StateTransition()
|
||||
|
||||
def _create_invoice(self, lines, purchase):
|
||||
invoice_lines = []
|
||||
for line in lines:
|
||||
line_ = line.get_invoice_line()
|
||||
invoice_lines.append(line_)
|
||||
|
||||
invoice_lines = list(chain(*invoice_lines))
|
||||
if not invoice_lines:
|
||||
return
|
||||
|
||||
invoice = purchase._get_invoice_purchase()
|
||||
if getattr(invoice, 'lines', None):
|
||||
invoice_lines = list(invoice.lines) + invoice_lines
|
||||
invoice.lines = invoice_lines
|
||||
invoice.save()
|
||||
|
||||
invoice.update_taxes()
|
||||
purchase.copy_resources_to(invoice)
|
||||
return invoice
|
||||
|
||||
def get_domain(self):
|
||||
return [
|
||||
('state', 'in', ['confirmed', 'processing', 'done']),
|
||||
('invoice_state', '=', 'none'),
|
||||
('party', '=', self.start.supplier.id),
|
||||
('currency', '=', self.start.currency.id),
|
||||
('delivery_date', '>=', self.start.start_date),
|
||||
('delivery_date', '<=', self.start.end_date),
|
||||
]
|
||||
|
||||
def get_order(self):
|
||||
return []
|
||||
|
||||
def transition_accept(self):
|
||||
pool = Pool()
|
||||
Purchase = pool.get('purchase.purchase')
|
||||
dom = self.get_domain()
|
||||
if self.start.ica_certicate:
|
||||
dom.append(
|
||||
('ica_certicate', '=', self.start.ica_certicate.id)
|
||||
)
|
||||
|
||||
purchases = Purchase.search(dom, order=self.get_order())
|
||||
if not purchases:
|
||||
return 'end'
|
||||
|
||||
lines_to_bill = []
|
||||
for purch in purchases:
|
||||
if purch.invoices:
|
||||
continue
|
||||
for line in purch.lines:
|
||||
lines_to_bill.append(line)
|
||||
|
||||
if lines_to_bill:
|
||||
self._create_invoice(lines_to_bill, purchases[0])
|
||||
return 'end'
|
||||
|
|
12
purchase.xml
12
purchase.xml
|
@ -162,5 +162,17 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="model">purchase.purchase,-1</field>
|
||||
<field name="action" ref="act_purchase_update"/>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="grouping_purchases_start_view_form">
|
||||
<field name="model">purchase.grouping_purchases.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">grouping_purchases_start_form</field>
|
||||
</record>
|
||||
<record model="ir.action.wizard" id="wizard_create_grouping_purchases">
|
||||
<field name="name">Grouping Purchases</field>
|
||||
<field name="wiz_name">purchase.grouping_purchases</field>
|
||||
</record>
|
||||
<menuitem name="Create Invoice of Purchases" parent="purchase.menu_purchase"
|
||||
sequence="2" id="menu_grouping_purchases"
|
||||
action="wizard_create_grouping_purchases"/>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
<?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>
|
||||
<label name="supplier"/>
|
||||
<field name="supplier"/>
|
||||
<label name="company"/>
|
||||
<field name="company" widget="selection"/>
|
||||
<label name="currency"/>
|
||||
<field name="currency"/>
|
||||
<label name="start_date"/>
|
||||
<field name="start_date"/>
|
||||
<label name="end_date"/>
|
||||
<field name="end_date"/>
|
||||
</form>
|
Loading…
Reference in New Issue