diff --git a/.~lock.supplier_certificate.fodt# b/.~lock.supplier_certificate.fodt# new file mode 100644 index 0000000..f3584d8 --- /dev/null +++ b/.~lock.supplier_certificate.fodt# @@ -0,0 +1 @@ +,presik,presik,20.11.2023 13:45,file:///home/presik/.config/libreoffice/4; \ No newline at end of file diff --git a/__init__.py b/__init__.py index 1cb114f..948b1e3 100644 --- a/__init__.py +++ b/__init__.py @@ -4,12 +4,15 @@ from trytond.pool import Pool from . import purchase from . import product +from . import account def register(): Pool.register( + account.PrintSupplierCertificateStart, product.Product, purchase.Configuration, + purchase.Party, purchase.Purchase, purchase.Line, purchase.PurchaseAnalyticStart, @@ -17,6 +20,7 @@ def register(): purchase.PurchaseUpdateStart, module='purchase_co', type_='model') Pool.register( + account.PrintSupplierCertificate, purchase.PurchasesDetailed, purchase.PurchaseAnalytic, purchase.PurchaseForceDraft, @@ -25,6 +29,7 @@ def register(): purchase.PurchaseUpdate, module='purchase_co', type_='wizard') Pool.register( + account.PrintSupplierCertificateReport, purchase.PurchasesDetailedReport, purchase.PurchaseAnalyticReport, module='purchase_co', type_='report') diff --git a/account.py b/account.py new file mode 100644 index 0000000..bf169b8 --- /dev/null +++ b/account.py @@ -0,0 +1,156 @@ +# 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 trytond.model import ModelView, fields +from trytond.wizard import Wizard, StateView, Button, StateReport +from trytond.report import Report +from trytond.pyson import Eval +from trytond.transaction import Transaction +from trytond.pool import Pool, PoolMeta +from trytond.exceptions import UserError +from datetime import date + +MONTHS = [ + 'enero', + 'febrero', + 'marzo', + 'abril', + 'mayo', + 'junio', + 'julio', + 'agosto', + 'septiembre', + 'octubre', + 'noviembre', + 'diciembre' +] + +conversor = None +try: + from numword import numword_es + conversor = numword_es.NumWordES() +except: + print("Warning: Does not possible import numword module, please install it...!") + + +class InvoiceAuthorization(metaclass=PoolMeta): + __name__ = 'account.invoice.authorization' + + # @classmethod + # def __setup__(cls): + # super().__setup__() + # cls.kind.selection.append(('supplier_certificate', "Supplier Certificate")) + + +class PrintSupplierCertificateStart(ModelView): + 'Print Supplier Certificate Start' + __name__ = 'purchase_co.print_supplier_certificate.start' + fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscalyear', + required=True) + company = fields.Many2One('company.company', 'Company', required=True) + party = fields.Many2One('party.party', 'Party') + start_period = fields.Many2One('account.period', 'Start Period', + domain=[ + ('fiscalyear', '=', Eval('fiscalyear')), + ('start_date', '<=', (Eval('end_period'), 'start_date')), + ], depends=['fiscalyear', 'end_period']) + end_period = fields.Many2One('account.period', 'End Period', + domain=[ + ('fiscalyear', '=', Eval('fiscalyear')), + ('start_date', '>=', (Eval('start_period'), 'start_date')) + ], + depends=['fiscalyear', 'start_period']) + description = fields.Char('Description') + + @staticmethod + def default_company(): + return Transaction().context.get('company') + + +class PrintSupplierCertificate(Wizard): + 'Print Supplier Certificate' + __name__ = 'purchase_co.print_supplier_certificate' + start = StateView('purchase_co.print_supplier_certificate.start', + 'purchase_co.print_supplier_certificate_start_view_form', [ + Button('Cancel', 'end', 'tryton-cancel'), + Button('Ok', 'print_', 'tryton-ok', default=True), + ]) + print_ = StateReport('purchase_co.print_supplier_certificate_report') + + def do_print_(self, action): + if self.start.start_period: + start_period = self.start.start_period.id + else: + start_period = None + if self.start.end_period: + end_period = self.start.end_period.id + else: + end_period = None + + party_id = None + if self.start.party: + party_id = self.start.party.id + data = { + 'company': self.start.company.id, + 'fiscalyear': self.start.fiscalyear.id, + 'party': party_id, + 'start_period': start_period, + 'end_period': end_period, + 'description': self.start.description + } + return action, data + + +class PrintSupplierCertificateReport(Report): + __name__ = 'purchase_co.print_supplier_certificate_report' + + @classmethod + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) + pool = Pool() + Company = pool.get('company.company') + Period = pool.get('account.period') + Party = pool.get('party.party') + User = pool.get('res.user') + Invoice = pool.get('account.invoice') + company = Company(data['company']) + start_period = None + end_period = None + dom_invoices = [ + ('party', '=', data['party']), + ] + if data['start_period']: + start_period = Period(data['start_period']) + dom_invoices.append(('invoice_date', '>=', start_period.start_date)) + + if data['end_period']: + end_period = Period(data['end_period']) + dom_invoices.append(('invoice_date', '<=', end_period.start_date)) + + invoices = Invoice.search(dom_invoices) + total_amount = 0 + for invoice in invoices: + total_amount += invoice.total_amount + + digits = company.currency.digits + print(digits, 'digits') + user_id = Transaction().user + report_context['num_in_words'] = cls.get_total_amount_words(total_amount, digits) + report_context['total_amount'] = total_amount + report_context['date_today'] = date.today() + report_context['start_period'] = start_period.start_date + report_context['end_period'] = end_period.start_date + report_context['party'] = Party(data['party']) + report_context['total_amount'] = total_amount + report_context['company'] = company + report_context['description'] = data['description'] + report_context['months'] = MONTHS + report_context['user'] = User(user_id) + return report_context + + @classmethod + def get_total_amount_words(cls, total_amount, digits): + if conversor and total_amount: + digits = digits + total_amount = (round(total_amount, digits)) + num = (conversor.cardinal(int(total_amount))).upper() + return num diff --git a/account.xml b/account.xml new file mode 100644 index 0000000..19e2489 --- /dev/null +++ b/account.xml @@ -0,0 +1,27 @@ + + + + + + + purchase_co.print_supplier_certificate.start + form + print_supplier_certificate_view_form + + + Print Supplier Certificate + purchase_co.print_supplier_certificate + + + Print Supplier Certificate + + purchase_co.print_supplier_certificate_report + purchase_co/supplier_certificate.fodt + odt + False + + + + \ No newline at end of file diff --git a/purchase.py b/purchase.py index b793d51..88225d0 100644 --- a/purchase.py +++ b/purchase.py @@ -20,6 +20,11 @@ class Configuration(metaclass=PoolMeta): help='See quantity in all warehouse') +class Party(metaclass=PoolMeta): + __name__ = 'party.party' + msm_cerfificate_supplier = fields.Char('msm Cerfificate Supplier') + + class Purchase(metaclass=PoolMeta): __name__ = 'purchase.purchase' iva = fields.Function(fields.Numeric('IVA'), 'get_tax_grouped') @@ -197,6 +202,15 @@ class Purchase(metaclass=PoolMeta): invoice.reference = self.reference return invoice + @classmethod + def delete(cls, purchases): + for purchase in purchases: + if purchase.number: + raise UserError( + 'No es posible eliminar compras que ya tengan asignado un consecutivo', + ) + super(Purchase, cls).delete(purchases) + class Line(metaclass=PoolMeta): __name__ = 'purchase.line' diff --git a/purchase.xml b/purchase.xml index 43161e1..a1ee19a 100644 --- a/purchase.xml +++ b/purchase.xml @@ -3,6 +3,11 @@ this repository contains the full copyright notices and license terms. --> + + party.party + + party_form + diff --git a/supplier_certificate.fodt b/supplier_certificate.fodt new file mode 100644 index 0000000..c256df1 --- /dev/null +++ b/supplier_certificate.fodt @@ -0,0 +1,526 @@ + + + + 2023-10-03T16:46:48.046638765LibreOffice/7.3.7.2$Linux_X86_64 LibreOffice_project/30$Build-22023-11-20T13:44:49.304097861PT2H7M25S29 + + + 0 + 0 + 26887 + 11599 + true + false + + + view2 + 4648 + 5168 + 0 + 0 + 26885 + 11598 + 0 + 1 + false + 180 + false + false + false + + + + + false + false + false + true + true + true + true + true + false + 0 + false + false + false + true + false + false + true + false + false + false + false + true + true + true + false + false + false + false + false + false + false + true + false + false + true + false + false + false + true + 0 + 1 + true + false + + high-resolution + true + + + false + false + true + false + true + true + false + true + + true + 1316254 + + true + false + true + true + 0 + + false + false + false + true + false + true + false + false + false + false + true + false + false + + false + false + true + false + false + false + false + false + false + false + false + false + 529220 + false + false + false + false + false + true + false + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $ + + + + + ( + $ + + ) + + + + $ + + + + + - + $ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <if test="company"> + <company.party.rec_name> + <if test="company.header"> + <for each="line in company.header.split('\n')"> + <line> + </for> + </if> + </if> + Carmen de Viboral, <date_today> + + + + + + + + + + CERTIFICA QUE: + <if test="party.type_document=='31'"> + Los señores <party.name>identificados con NIT <party.id_number>prestaron sus servicios tal como se describen a continuación: + </if> + <if test="party.type_document!='31'"> + El/la señor/a <party.name>identificado con <party.type_document_string>prestó sus servicios tal como se describen a continuación: + </if> + Objeto: <description> + + Fecha Inicio: <start_period> + Fecha Final: <end_period> + + valor de los servicios prestados: <num_in_words>(<format_currency(total_amount, company.party.lang, company.currency)>). Valor antes de impuestos + + + <if test="end_period"> + Durante el periodo <start_period>hasta el periodo <end_period>, <party.msm_cerfificate_supplier> + + En constancia de lo anterior, se firma en Barrancabermeja, a los <date_today.day>días del mes <months[date_today.month]>de <date_today.year> + + </if> + + + + + + + + + + + + + <user.name> + <user.employees[0].position.name> + <company.party.id_number> + <company.party.rec_name> + + + + \ No newline at end of file diff --git a/tryton.cfg b/tryton.cfg index 1c4d42f..b360ecd 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -7,3 +7,4 @@ depends: xml: purchase.xml product.xml + account.xml diff --git a/view/party_form.xml b/view/party_form.xml new file mode 100644 index 0000000..065ae4d --- /dev/null +++ b/view/party_form.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/view/print_supplier_certificate_view_form.xml b/view/print_supplier_certificate_view_form.xml new file mode 100644 index 0000000..a3506bd --- /dev/null +++ b/view/print_supplier_certificate_view_form.xml @@ -0,0 +1,17 @@ + + +
+