diff --git a/__init__.py b/__init__.py index 230cc2c..dd92f22 100644 --- a/__init__.py +++ b/__init__.py @@ -19,6 +19,8 @@ def register(): sale.Sale, sale.SaleForceDraft, sale.SaleLine, + sale.SaleLineHistoryDelete, + sale.SaleLineHistoryDeleteStart, sale.SaleMove, shop.SaleShop, production.Production, @@ -29,7 +31,9 @@ def register(): module='sale_pos_frontend_rest', type_='model') Pool.register( sale.SaleSquareBoxGlobal, + sale.SaleLineHistoryDeleteWizard, module='sale_pos_frontend_rest', type_='wizard') Pool.register( sale.SaleSquareBoxGlobalReport, + sale.SaleLineHistoryDeleteReport, module='sale_pos_frontend_rest', type_='report') diff --git a/history_delete_product.fods b/history_delete_product.fods new file mode 100644 index 0000000..79c1c81 --- /dev/null +++ b/history_delete_product.fods @@ -0,0 +1,1009 @@ + + + + 2022-11-21T16:14:45.9668377182022-11-22T09:59:37.016241195PT16M35S7LibreOffice/7.3.6.2$Linux_X86_64 LibreOffice_project/30$Build-2 + + + 0 + 0 + 22588 + 5211 + + + view1 + + + 3 + 14 + 2 + 0 + 0 + 0 + 0 + 0 + 160 + 60 + false + false + + + Sheet1 + 1834 + 0 + 160 + 60 + false + true + true + true + 12632256 + true + true + true + true + false + false + false + 1270 + 1270 + 1 + 1 + true + false + + + + + true + true + true + 0 + true + true + false + true + false + 12632256 + true + true + false + false + true + true + false + 3 + false + SAT23TUSE + false + lgH+/1NBVDIzVFVTRQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQ1VQUzpTQVQyM1RVU0UAAAAAAAAAAAAAAAAAAAAAAAAWAAMAswAAAAAAAAAIAFZUAAAkbQAASm9iRGF0YSAxCnByaW50ZXI9U0FUMjNUVVNFCm9yaWVudGF0aW9uPVBvcnRyYWl0CmNvcGllcz0xCmNvbGxhdGU9ZmFsc2UKbWFyZ2luYWRqdXN0bWVudD0wLDAsMCwwCmNvbG9yZGVwdGg9MjQKcHNsZXZlbD0wCnBkZmRldmljZT0xCmNvbG9yZGV2aWNlPTAKUFBEQ29udGV4dERhdGEKUGFnZVNpemU6TGV0dGVyAAASAENPTVBBVF9EVVBMRVhfTU9ERRMARHVwbGV4TW9kZTo6VW5rbm93bg== + false + 1270 + 1270 + 1 + 1 + true + false + true + true + true + true + 7 + true + + + Sheet1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + / + + / + + + + + + + + + + pta + + + - + + + pta + + + + - pta + + + + + + + + + + $ + + + + + - + $ + + + + + $ + + + + + + $ + + ( + + ) + + + $ + + - + + + + + + + + + + + + + + + - + + + + + + + - + + + + + + + + + + + + + + + + - + + + + + + - + - + + + + + + + + - + + + + + $ + + + + + + $ + + - + + + + + $ + + - + + + + + + + + + + + + + + + + ( + + ) + + + + - + + + + + + + + + + $ + + + + + + $ + + - + + + + + $ + + - + + + + + + + + + + + + + - + + - + + + + + + + + + + - + + + + + + - + + + + + + + + + + + + + + + + + + ( + + ) + + + + - + + + + + + + + + + + + + % + + + + - + + % + + + + + + + + + - + + + + + + + - + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + - + + + + + + + + - + + + + + + + $ + + + + + ($ + + ) + + + + $ + + + + + ( + $ + + ) + + + + + + + + + + - + + + + + + - + + + + + + + + + + + + + + + + : + + . + + + + : + + : + + + + + : + + + + + + + + + + - + + + + + + + + + - + + + + + + + + + + + + + + + + - + + + + + + + + - + + + + + + + + + - + + + + + + + + - + + + + + + - + + + + + - + + + + + - + + - + + + + + + + + + + - + + + + + + + + de + + de + + + + + + + + + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + / + + / + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ??? + + + + + Page 1 + + + + + + + + + + + + + + company.party.name + + + + + + + + + + PRODUCTOS ELIMINADOS EN VENTAS + + + + + + + + + + FECHA INICIO: + + data['start_date'] + + + + FECHA FIN: + + data['end_date'] + + + + TIENDA + + shop_name + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FECHA + + + COD + + + NOMBRE + + + CANTIDAD + + + VALOR UNITARIO + + + TIENDA + + + ESTADO ORDEN + + + ESTADO VENTA + + + USUARIO + + + + + + for each='line in records' + + + + + + + + line.date + + line.product.code + + line.product.name + + line.quantity + + line.unit_price + + line.shop.name + + line.order_status + + line.sale_state + + line.create_uid.name + + + + + + /for + + + + + + + + + + + + + + + Impresión: + + company.time_now() + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sale.py b/sale.py index f66cddc..455e87f 100644 --- a/sale.py +++ b/sale.py @@ -4,10 +4,13 @@ from __future__ import unicode_literals from datetime import date, datetime from sql import Table from trytond.pool import PoolMeta, Pool -from trytond.model import fields, ModelSQL +from trytond.model import fields, ModelSQL, ModelView +from trytond.modules.product import price_digits from trytond.pyson import Eval from trytond.transaction import Transaction -from trytond.wizard import Wizard +from trytond.wizard import ( + Wizard, StateTransition, StateView, Button, StateReport +) from decimal import Decimal from trytond.wizard import StateReport from trytond.report import Report @@ -81,7 +84,6 @@ class Sale(metaclass=PoolMeta): if tables: ShopTable.write(tables, {'sale': None, 'state':'available'}) - @classmethod def transition_pay_(cls, sales_to_pay): pool = Pool() @@ -314,6 +316,124 @@ class SaleLine(metaclass=PoolMeta): __name__ = 'sale.line' production = fields.Many2One('production', 'Production') + @classmethod + def delete(cls, lines): + HistoryDelete = Pool().get('sale.line._history.delete') + lines_to_create = [] + lines_to_create_append = lines_to_create.append + for line in lines: + if line.order_sended: + value = { + 'line_id': line.id, + 'product': line.product, + 'quantity': line.quantity, + 'date': line.sale.sale_date, + 'order_status': line.sale.order_status, + 'sale_state': line.sale.state, + 'unit_price': line.unit_price, + 'base_price': line.base_price, + 'shop': line.sale.shop + } + lines_to_create_append(value) + super(SaleLine, cls).delete(lines) + if lines_to_create: + HistoryDelete.create(lines_to_create) + + +class SaleLineHistoryDelete(ModelView, ModelSQL): + 'Sale Line History Delete' + __name__ = 'sale.line._history.delete' + + product = fields.Many2One('product.product', 'Product') + line_id = fields.Char('Line id') + order_status = fields.Char('Order Status') + sale_state = fields.Char('Sale State') + quantity = fields.Float('Quantity', + digits=(16, Eval('unit_digits', 2))) + shop = fields.Many2One('sale.shop', 'Shop') + unit_price = fields.Numeric('Unit Price', digits=price_digits) + date = fields.Date('Date') + base_price = fields.Numeric('Base Price', digits=price_digits) + + +class SaleLineHistoryDeleteStart(ModelSQL, ModelView): + 'Sale Line History Delete Start' + __name__ = 'line_history.delete_start' + + company = fields.Many2One('company.company', 'Company', required=True) + start_date = fields.Date('Date', required=True) + end_date = fields.Date('Date', required=True) + shop = fields.Many2One('sale.shop', 'Shop', required=True) + + @staticmethod + def default_company(): + return Transaction().context.get('company') + + @staticmethod + def default_shop(): + return Transaction().context.get('shop') + + @staticmethod + def default_end_date(): + Date = Pool().get('ir.date') + return Date.today() + + @staticmethod + def default_start_date(): + Date = Pool().get('ir.date') + today = Date.today() + date_ = date(today.year, today.month, 1) + return date_ + + +class SaleLineHistoryDeleteWizard(Wizard): + 'Sale Line History Delete' + __name__ = 'line_history.delete_wizard' + + start = StateView('line_history.delete_start', + 'sale_pos_frontend_rest.line_history_delete_view_form', [ + Button('Cancel', 'end', 'tryton-cancel'), + Button('Print', 'print_', 'tryton-ok', default=True), + ]) + print_ = StateReport('line_history.delete_report') + + def do_print_(self, action): + report_context = { + 'company': self.start.company.id, + 'start_date': self.start.start_date, + 'end_date': self.start.end_date, + 'shop': self.start.shop.id, + } + return action, report_context + + def transition_print_(self): + return 'end' + + +class SaleLineHistoryDeleteReport(Report): + 'Sale Line History Delete Report' + __name__ = 'line_history.delete_report' + + @classmethod + def get_context(cls, records, header, data): + report_context = super().get_context(records, header, data) + pool = Pool() + History = pool.get('sale.line._history.delete') + Company = pool.get('company.company') + Shop = pool.get('sale.shop') + domain = [ + ('date', '>=', data['start_date']), + ('date', '<=', data['end_date']), + ] + records = History.search_read(domain) + record_ids = [r['id'] for r in records] + records = cls._get_records(record_ids, 'sale.line._history.delete', data) + company = Company(data['company']) + report_context['company'] = company + report_context['shop_name'] = Shop.name + report_context['records'] = records + return report_context + class SaleSquareBoxGlobal(SaleSquareBox): 'Sale Square Box Global' diff --git a/sale.xml b/sale.xml index d1c98ab..bf11417 100644 --- a/sale.xml +++ b/sale.xml @@ -36,5 +36,26 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig id="menu_sale_square_box_global" icon="tryton-print" action="wizard_print_sale_square_box_global" sequence="100"/> + + Report History Delete Product + + line_history.delete_report + sale_pos_frontend_rest/history_delete_product.fods + ods + False + + + line_history.delete_start + form + line_history_delete_view_form + + + History Delete Products + line_history.delete_wizard + + + diff --git a/setup.py b/setup.py index 42c29c9..8365e35 100644 --- a/setup.py +++ b/setup.py @@ -76,7 +76,7 @@ setup(name=name, ], package_data={ 'trytond.modules.%s' % MODULE: (info.get('xml', []) - + ['tryton.cfg', 'view/*.xml', 'locale/*.po', '*.odt', '*.ods']), + + ['tryton.cfg', 'view/*.xml', 'locale/*.po', '*.odt', '*.ods', '*.fodt', '*.fods']), }, classifiers=[ 'Development Status :: 5 - Production/Stable', diff --git a/view/line_history_delete_view_form.xml b/view/line_history_delete_view_form.xml new file mode 100644 index 0000000..541d8ec --- /dev/null +++ b/view/line_history_delete_view_form.xml @@ -0,0 +1,13 @@ + + +
+