Feat: Lineas eliminadas
This commit is contained in:
commit
6157328b80
@ -10,6 +10,7 @@ def register():
|
|||||||
invoice.InvoiceLine,
|
invoice.InvoiceLine,
|
||||||
sale.Sale,
|
sale.Sale,
|
||||||
sale.Line,
|
sale.Line,
|
||||||
|
sale.SaleLineDeletedLog,
|
||||||
user.User,
|
user.User,
|
||||||
production.Production,
|
production.Production,
|
||||||
report_close_statement.ReportCloseStatementStart,
|
report_close_statement.ReportCloseStatementStart,
|
||||||
|
25
sale.py
25
sale.py
@ -204,10 +204,16 @@ class Sale(metaclass=PoolMeta):
|
|||||||
"uom": line.unit.name if line.type != 'title' else None}
|
"uom": line.unit.name if line.type != 'title' else None}
|
||||||
for line in report.lines if not line.impreso]
|
for line in report.lines if not line.impreso]
|
||||||
data["deleted_lines"] = [{
|
data["deleted_lines"] = [{
|
||||||
|
<<<<<<< HEAD
|
||||||
"product": line.product.name,
|
"product": line.product.name,
|
||||||
"quantity": str(-1 * line.quantity),
|
"quantity": str(-1 * line.quantity),
|
||||||
"unit": line.unit.symbol,
|
"unit": line.unit.symbol,
|
||||||
} for line in report.delete_lines if not line.printed]
|
} for line in report.delete_lines if not line.printed]
|
||||||
|
=======
|
||||||
|
"product": line.product.name if line.type != 'title' else None,
|
||||||
|
"quantity": line.quantity if line.type != 'title' else None,
|
||||||
|
} for line in report.delete_lines if not line.impreso]
|
||||||
|
>>>>>>> 77d626374f847b8e54b81cc06f76b545e4014b29
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@ -232,7 +238,11 @@ class Sale(metaclass=PoolMeta):
|
|||||||
line.save()
|
line.save()
|
||||||
|
|
||||||
for line in record.delete_lines:
|
for line in record.delete_lines:
|
||||||
|
<<<<<<< HEAD
|
||||||
line.printed = True
|
line.printed = True
|
||||||
|
=======
|
||||||
|
line.impreso = True
|
||||||
|
>>>>>>> 77d626374f847b8e54b81cc06f76b545e4014b29
|
||||||
line.save()
|
line.save()
|
||||||
record.save()
|
record.save()
|
||||||
|
|
||||||
@ -382,9 +392,17 @@ class Line(metaclass=PoolMeta):
|
|||||||
impreso = fields.Boolean("Impreso")
|
impreso = fields.Boolean("Impreso")
|
||||||
bought_pizza = fields.Boolean("Sold pizza")
|
bought_pizza = fields.Boolean("Sold pizza")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def delete(cls, lines):
|
||||||
|
for line in lines:
|
||||||
|
if line.impreso:
|
||||||
|
cls._create_sale_line_deleted_log(line)
|
||||||
|
super(Line, cls).delete(lines)
|
||||||
|
|
||||||
@fields.depends('product', 'unit', 'sale',
|
@fields.depends('product', 'unit', 'sale',
|
||||||
'_parent_sale.party', '_parent_sale.invoice_party',
|
'_parent_sale.party', '_parent_sale.invoice_party',
|
||||||
'_parent_sale.pizza_number',
|
'_parent_sale.pizza_number',
|
||||||
|
'_parent_product.pizza',
|
||||||
methods=['compute_taxes', 'compute_unit_price',
|
methods=['compute_taxes', 'compute_unit_price',
|
||||||
'on_change_with_amount'])
|
'on_change_with_amount'])
|
||||||
def on_change_product(self):
|
def on_change_product(self):
|
||||||
@ -400,3 +418,10 @@ class Line(metaclass=PoolMeta):
|
|||||||
Production = super(Line, self).get_production(product_quantities)
|
Production = super(Line, self).get_production(product_quantities)
|
||||||
|
|
||||||
return Production
|
return Production
|
||||||
|
|
||||||
|
|
||||||
|
class SaleLineDeletedLog(metaclass=PoolMeta):
|
||||||
|
"""Sale Line Deleted Log"""
|
||||||
|
__name__ = 'sale.line_deleted'
|
||||||
|
|
||||||
|
printed = fields.Boolean("Printed")
|
||||||
|
209
tests/scenario_sale_fast_food.rst
Normal file
209
tests/scenario_sale_fast_food.rst
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
=============================
|
||||||
|
Sale Line Delete Log Scenario
|
||||||
|
=============================
|
||||||
|
|
||||||
|
Imports::
|
||||||
|
>>> from decimal import Decimal
|
||||||
|
>>> from proteus import Model, Wizard
|
||||||
|
>>> from trytond.tests.tools import activate_modules
|
||||||
|
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||||
|
>>> from trytond.modules.account.tests.tools import (
|
||||||
|
... create_chart, create_fiscalyear, create_tax, get_accounts)
|
||||||
|
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||||
|
... create_payment_term, set_fiscalyear_invoice_sequences)
|
||||||
|
>>> import datetime as dt
|
||||||
|
>>> today = dt.date.today()
|
||||||
|
>>> from trytond.tests.tools import set_user
|
||||||
|
>>> from trytond.modules.sale_shop.tests.tools import create_shop
|
||||||
|
>>> from trytond.modules.sale_line_delete_log.sale import SaleLineDeleted
|
||||||
|
|
||||||
|
Activate modules::
|
||||||
|
|
||||||
|
>>> config = activate_modules('sale_fast_food')
|
||||||
|
|
||||||
|
Initial data::
|
||||||
|
|
||||||
|
>>> User = Model.get('res.user')
|
||||||
|
>>> Party = Model.get('party.party')
|
||||||
|
>>> Employee = Model.get('company.employee')
|
||||||
|
>>> Journal = Model.get('account.journal')
|
||||||
|
>>> PaymentMethod = Model.get('account.invoice.payment.method')
|
||||||
|
>>> Party = Model.get('party.party')
|
||||||
|
>>> ProductUom = Model.get('product.uom')
|
||||||
|
>>> ProductTemplate = Model.get('product.template')
|
||||||
|
>>> Sale = Model.get('sale.sale')
|
||||||
|
>>> SaleLine = Model.get('sale.line')
|
||||||
|
|
||||||
|
Create company::
|
||||||
|
|
||||||
|
>>> _ = create_company()
|
||||||
|
>>> company = get_company()
|
||||||
|
|
||||||
|
Set employee::
|
||||||
|
|
||||||
|
>>> employee_party = Party(name="Employee")
|
||||||
|
>>> employee_party.save()
|
||||||
|
>>> employee = Employee(party=employee_party)
|
||||||
|
>>> employee.save()
|
||||||
|
>>> user = User(config.user)
|
||||||
|
>>> user.employees.append(employee)
|
||||||
|
>>> user.employee = employee
|
||||||
|
>>> user.save()
|
||||||
|
>>> set_user(user.id)
|
||||||
|
|
||||||
|
Create fiscal year::
|
||||||
|
|
||||||
|
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear(company, today))
|
||||||
|
>>> fiscalyear.click('create_period')
|
||||||
|
|
||||||
|
Create chart of accounts::
|
||||||
|
|
||||||
|
>>> _ = create_chart(company)
|
||||||
|
>>> accounts = get_accounts(company)
|
||||||
|
>>> revenue = accounts['revenue']
|
||||||
|
>>> expense = accounts['expense']
|
||||||
|
>>> cash = accounts['cash']
|
||||||
|
|
||||||
|
>>> cash_journal, = Journal.find([('type', '=', 'cash')])
|
||||||
|
>>> cash_journal.save()
|
||||||
|
>>> payment_method = PaymentMethod()
|
||||||
|
>>> payment_method.name = 'Cash'
|
||||||
|
>>> payment_method.journal = cash_journal
|
||||||
|
>>> payment_method.credit_account = cash
|
||||||
|
>>> payment_method.debit_account = cash
|
||||||
|
>>> payment_method.save()
|
||||||
|
|
||||||
|
Create tax::
|
||||||
|
|
||||||
|
>>> tax = create_tax(Decimal('.10'))
|
||||||
|
>>> tax.save()
|
||||||
|
|
||||||
|
Create parties::
|
||||||
|
|
||||||
|
>>> supplier = Party(name='Supplier')
|
||||||
|
>>> supplier.save()
|
||||||
|
>>> customer = Party(name='Customer')
|
||||||
|
>>> customer.save()
|
||||||
|
|
||||||
|
Create account categories::
|
||||||
|
|
||||||
|
>>> ProductCategory = Model.get('product.category')
|
||||||
|
>>> account_category = ProductCategory(name="Account Category")
|
||||||
|
>>> account_category.accounting = True
|
||||||
|
>>> account_category.account_expense = expense
|
||||||
|
>>> account_category.account_revenue = revenue
|
||||||
|
>>> account_category.save()
|
||||||
|
|
||||||
|
>>> account_category_tax, = account_category.duplicate()
|
||||||
|
>>> account_category_tax.customer_taxes.append(tax)
|
||||||
|
>>> account_category_tax.save()
|
||||||
|
|
||||||
|
Create product::
|
||||||
|
|
||||||
|
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||||
|
|
||||||
|
>>> template = ProductTemplate()
|
||||||
|
>>> template.name = 'product'
|
||||||
|
>>> template.default_uom = unit
|
||||||
|
>>> template.type = 'goods'
|
||||||
|
>>> template.salable = True
|
||||||
|
>>> template.list_price = Decimal('10')
|
||||||
|
>>> template.account_category = account_category_tax
|
||||||
|
>>> template.save()
|
||||||
|
>>> product, = template.products
|
||||||
|
|
||||||
|
>>> template = ProductTemplate()
|
||||||
|
>>> template.name = 'service'
|
||||||
|
>>> template.default_uom = unit
|
||||||
|
>>> template.type = 'service'
|
||||||
|
>>> template.salable = True
|
||||||
|
>>> template.list_price = Decimal('30')
|
||||||
|
>>> template.account_category = account_category
|
||||||
|
>>> template.save()
|
||||||
|
>>> service, = template.products
|
||||||
|
|
||||||
|
Create payment term::
|
||||||
|
|
||||||
|
>>> payment_term = create_payment_term()
|
||||||
|
>>> payment_term.save()
|
||||||
|
|
||||||
|
Create product price list::
|
||||||
|
|
||||||
|
>>> ProductPriceList = Model.get('product.price_list')
|
||||||
|
>>> product_price_list = ProductPriceList()
|
||||||
|
>>> product_price_list.name = 'Price List'
|
||||||
|
>>> product_price_list.company = company
|
||||||
|
>>> product_price_list.save()
|
||||||
|
|
||||||
|
Create an Inventory::
|
||||||
|
|
||||||
|
>>> Inventory = Model.get('stock.inventory')
|
||||||
|
>>> Location = Model.get('stock.location')
|
||||||
|
>>> storage, = Location.find([
|
||||||
|
... ('code', '=', 'STO'),
|
||||||
|
... ])
|
||||||
|
>>> inventory = Inventory()
|
||||||
|
>>> inventory.location = storage
|
||||||
|
>>> inventory_line = inventory.lines.new(product=product)
|
||||||
|
>>> inventory_line.quantity = 100.0
|
||||||
|
>>> inventory_line.expected_quantity = 0.0
|
||||||
|
>>> inventory.click('confirm')
|
||||||
|
>>> inventory.state
|
||||||
|
'done'
|
||||||
|
|
||||||
|
Create Sale Shop::
|
||||||
|
|
||||||
|
>>> shop = create_shop(payment_term, product_price_list)
|
||||||
|
>>> shop.save()
|
||||||
|
|
||||||
|
Save Sale Shop User::
|
||||||
|
|
||||||
|
>>> User = Model.get('res.user')
|
||||||
|
>>> user, = User.find([])
|
||||||
|
>>> user.shops.append(shop)
|
||||||
|
>>> user.shop = shop
|
||||||
|
>>> user.save()
|
||||||
|
>>> set_user(user)
|
||||||
|
|
||||||
|
Sale 5 products::
|
||||||
|
|
||||||
|
>>> sale = Sale()
|
||||||
|
>>> sale.party = customer
|
||||||
|
>>> sale.payment_term = payment_term
|
||||||
|
>>> sale.invoice_method = 'order'
|
||||||
|
>>> sale_line = SaleLine()
|
||||||
|
>>> sale.lines.append(sale_line)
|
||||||
|
>>> sale_line.product = product
|
||||||
|
>>> sale_line.quantity = 2.0
|
||||||
|
>>> sale_line.impreso = True
|
||||||
|
>>> sale_line = SaleLine()
|
||||||
|
>>> sale.lines.append(sale_line)
|
||||||
|
>>> sale_line.type = 'comment'
|
||||||
|
>>> sale_line.description = 'Comment'
|
||||||
|
>>> sale_line = SaleLine()
|
||||||
|
>>> sale.lines.append(sale_line)
|
||||||
|
>>> sale_line.product = product
|
||||||
|
>>> sale_line.quantity = 3.0
|
||||||
|
>>> sale.save()
|
||||||
|
>>> len(sale.lines)
|
||||||
|
3
|
||||||
|
>>> sale.untaxed_amount, sale.tax_amount, sale.total_amount
|
||||||
|
(Decimal('50.00'), Decimal('5.00'), Decimal('55.00'))
|
||||||
|
|
||||||
|
|
||||||
|
Create a sale line delete log it's was printed::
|
||||||
|
|
||||||
|
>>> sale.reload()
|
||||||
|
>>> sale.lines[0].delete()
|
||||||
|
>>> sale.lines[1].delete()
|
||||||
|
>>> sale.save()
|
||||||
|
>>> len(sale.lines)
|
||||||
|
1
|
||||||
|
|
||||||
|
>>> sale.reload()
|
||||||
|
>>> len(sale.delete_lines)
|
||||||
|
1
|
||||||
|
|
||||||
|
>>> sale.delete_lines[0]
|
||||||
|
proteus.Model.get('sale.line_deleted')(1)
|
||||||
|
>>> assert isinstance(sale.delete_lines[0], Model.get('sale.line_deleted')), "it's not instance SaleLineDeleted"
|
8
tests/test_scenario.py
Normal file
8
tests/test_scenario.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# 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.tests.test_tryton import load_doc_tests
|
||||||
|
|
||||||
|
|
||||||
|
def load_tests(*args, **kwargs):
|
||||||
|
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
@ -5,7 +5,9 @@ depends:
|
|||||||
res
|
res
|
||||||
product
|
product
|
||||||
sale
|
sale
|
||||||
|
sale_discount
|
||||||
sale_supply_production
|
sale_supply_production
|
||||||
|
sale_line_delete_log
|
||||||
sale_printer
|
sale_printer
|
||||||
production
|
production
|
||||||
account_invoice
|
account_invoice
|
||||||
@ -15,4 +17,4 @@ xml:
|
|||||||
product.xml
|
product.xml
|
||||||
sale.xml
|
sale.xml
|
||||||
user.xml
|
user.xml
|
||||||
report_close_statement.xml
|
report_close_statement.xml
|
||||||
|
Loading…
Reference in New Issue
Block a user