minor fix

This commit is contained in:
wilson gomez 2021-12-10 10:17:22 -05:00
parent 4c9697dc5e
commit 60efecf4e6
4 changed files with 43 additions and 19 deletions

View file

@ -1,7 +1,7 @@
import locale
from PyQt5.QtWidgets import (
QLineEdit, QLabel, QComboBox, QGridLayout, QTextEdit, QTreeView,
QCompleter, QCalendarWidget
QCompleter, QCalendarWidget, QCheckBox
)
from PyQt5.QtCore import Qt, QRegExp
from PyQt5.QtGui import QRegExpValidator, QDoubleValidator
@ -16,7 +16,7 @@ try:
except:
print("Warning: Error setting locale")
__all__ = ['Label', 'Field', 'ComboBox', 'GridForm', 'FieldMoney', 'FieldDate']
__all__ = ['Label', 'Field', 'ComboBox', 'GridForm', 'FieldMoney', 'FieldDate', 'CheckBox']
def set_object_name(obj, type_, value):
@ -144,6 +144,16 @@ class TextField(QTextEdit):
self.value_changed = True
class CheckBox(QCheckBox):
def __init__(self, obj, key, value, form=None):
super(CheckBox, self).__init__()
self.key = key
self.form = form
setattr(obj, 'field_' + key, self)
self.setText(value.get('name'))
class FieldDate(QCalendarWidget):
def __init__(self, obj, key, value, form=None):
@ -415,6 +425,9 @@ class GridForm(QGridLayout):
_field = FieldInput(obj, key, value, form=self)
elif value.get('type') == 'selection':
_field = ComboBox(obj, key, value, form=self)
elif value.get('type') == 'checkbox':
_field = CheckBox(obj, key, value, form=self)
expand = 1
elif value.get('type') == 'money':
_field = FieldMoney(obj, key, value, form=self)
elif value.get('type') == 'text':

View file

@ -656,6 +656,11 @@ class DialogPrintInvoice(QuickDialog):
(2, 'LASER')
],
}),
('resend_dian_ask', {
'name': 'REENVIO DIAN',
'type': 'checkbox',
'placeholder': 'REENVIO DIAN',
}),
]
super(DialogPrintInvoice, self).__init__(parent, 'action', data=view)

View file

@ -1366,6 +1366,7 @@ class AppWindow(FrontWindow):
if res == DIALOG_REPLY_NO:
return
number = self.field_invoice_number_ask.text()
resend_dian = self.resend_dian_ask.isChecked()
printer_id = self.field_printer_ask.get_id()
type_doc = self.field_type_ask.get_id()
sale_id = None
@ -1492,6 +1493,7 @@ class AppWindow(FrontWindow):
price = Decimal(price_w_tax) - (discount/Decimal(line['quantity']))
if price < 0:
price = 0
# Fixme set_discount_on_direct
res = self.set_unit_price(price)
else:
@ -2047,7 +2049,7 @@ class AppWindow(FrontWindow):
if list_price < list_price_r:
# Update price in selected_line
self.set_unit_price(product_r[0]['template']['sale_price_w_tax'])
self.set_unit_price(product_r[0]['template']['sale_price_w_tax'], discount=False)
list_price = None
self.on_selected_item(record, list_price)
self.dialog_combine_product.close()
@ -2796,6 +2798,7 @@ class AppWindow(FrontWindow):
records = self.SaleLine.faster_set_discount({
'line_ids': target_lines,
'value': value,
'type': type_,
})
for rec in records:
self.model_sale_lines.update_record(rec)
@ -2805,10 +2808,11 @@ class AppWindow(FrontWindow):
self.set_amounts()
return res
def set_unit_price(self, value):
def set_unit_price(self, value, discount=None):
rec = self.SaleLine.set_faster_unit_price({
'id': self._current_line_id,
'value': value,
'discount': discount,
})
if rec:
@ -3050,7 +3054,9 @@ class AppWindow(FrontWindow):
self._current_line_id = line['id']
if unit_price:
diff = abs(current_unit_price - float(unit_price))
if diff > 1:
if float(unit_price) > current_unit_price:
self.set_unit_price(unit_price, discount=False)
elif diff > 1:
self._sign = '/'
self._process_price(unit_price, line)
self._sign = None

View file

@ -462,16 +462,16 @@ class Receipt(object):
print(line)
discount = line.get('discount')
print('discount...', discount)
# if self._show_discount and discount and Decimal(discount) > 0:
# amount_w_tax = Decimal(line['amount_w_tax'])
# discount = Decimal(discount)
# initial = 'DCTO - ' + str(round(discount*100, 0)) + '%'
# if discount == 1:
# line_total = 0
# else:
# line_total = amount_w_tax/(1-discount)
# discount = '-' + money(line_total - amount_w_tax)
# line_total = money(line_total)
if self._show_discount and discount and Decimal(discount) > 0:
amount_w_tax = Decimal(line['amount_w_tax'])
discount = Decimal(discount)
initial = 'DCTO - ' + str(round(discount*100, 0)) + '%'
if discount == 1:
line_total = 0
else:
line_total = amount_w_tax/(1-discount)
discount = '-' + money(line_total - amount_w_tax)
line_total = money(line_total)
code = line['code'] or ' '
if line['quantity'] != 1:
@ -488,16 +488,16 @@ class Receipt(object):
line['quantity'], unit_price_w_tax)
second_line = second_line.encode('utf-8')
self.print_split(second_line, line_total)
# if self._show_discount and discount and Decimal(discount):
# self.print_split(initial, discount)
if self._show_discount and discount and Decimal(discount):
self.print_split(initial, discount)
else:
if self._environment == 'retail':
line_pt = code + ' ' + line['name'][:len_row]
else:
line_pt = line['name'][:len_row]
self.print_split(line_pt, line_total)
# if line['discount'] and Decimal(line['discount']) and self._show_discount:
# self.print_split(initial, discount)
if line['discount'] and Decimal(line['discount']) and self._show_discount:
self.print_split(initial, discount)
def print_totals(self, sale):
untaxed_amount = sale['untaxed_amount']