Release v6.0

This commit is contained in:
wilson gomez 2021-06-22 13:38:52 -05:00
parent a19d93e995
commit fadb77a671
14 changed files with 95 additions and 103 deletions

View file

@ -2,15 +2,15 @@
# The COPYRIGHT file at the top level of this repository contains # The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms. # the full copyright notices and license terms.
from trytond.pool import Pool from trytond.pool import Pool
import shop from . import shop
import sale from . import sale
import user from . import user
import configuration from . import configuration
import stock from . import stock
import invoice from . import invoice
import price_list from . import price_list
import product from . import product
import source from . import source
def register(): def register():

View file

@ -3,8 +3,6 @@
from trytond.model import fields from trytond.model import fields
from trytond.pool import PoolMeta from trytond.pool import PoolMeta
__all__ = ['Configuration']
class Configuration(metaclass=PoolMeta): class Configuration(metaclass=PoolMeta):
__name__ = 'sale.configuration' __name__ = 'sale.configuration'

16
exceptions.py Normal file
View file

@ -0,0 +1,16 @@
# 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.exceptions import UserError
from trytond.model.exceptions import ValidationError
class SaleMissingSequenceError(ValidationError):
pass
class ShopUserError(UserError):
pass
class SaleWriteError(UserError):
pass

View file

@ -5,8 +5,6 @@ from trytond.model import fields
from trytond.pool import PoolMeta from trytond.pool import PoolMeta
from trytond.pyson import Eval from trytond.pyson import Eval
__all__ = ['Invoice', 'InvoicesStart', 'Invoices', 'InvoicesReport']
class Invoice(metaclass=PoolMeta): class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice' __name__ = 'account.invoice'

23
message.xml Normal file
View file

@ -0,0 +1,23 @@
<?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. -->
<tryton>
<data grouped="1">
<record model="ir.message" id="msg_not_sale_shop">
<field name="text">Go to user preferences and select a shop "%(s)"</field>
</record>
<record model="ir.message" id="msg_no_return_sequence">
<field name="text">Return Sale Sequence is missing!</field>
</record>
<record model="ir.message" id="msg_sale_not_shop">
<field name="text">Sale have not related a shop</field>
</record>
<record model="ir.message" id="msg_edit_sale_by_shop">
<field name="text">You cannot edit this order because you do not have permission to edit in this shop.</field>
</record>
<record model="ir.message" id="msg_sale_not_product">
<field name="text">The sale "%(s)" dont have product </field>
</record>
</data>
</tryton>

View file

@ -12,8 +12,6 @@ from trytond.wizard import (
Wizard, StateView, StateReport, Button Wizard, StateView, StateReport, Button
) )
__all__ = ['PriceListLine']
class PriceListLine(metaclass=PoolMeta): class PriceListLine(metaclass=PoolMeta):
__name__ = 'product.price_list.line' __name__ = 'product.price_list.line'
@ -53,8 +51,8 @@ class ProductPriceList(Report):
data=None data=None
@classmethod @classmethod
def get_context(cls, records, data): def get_context(cls, records, header, data):
report_context = super(ProductPriceList, cls).get_context(records, data) report_context = super().get_context(records, header, data)
for record in records: for record in records:
for l in record.lines: for l in record.lines:
unit_price = l.product.list_price unit_price = l.product.list_price
@ -118,9 +116,8 @@ class PriceListBySupplierReport(Report):
__name__ = 'sale_shop.price_list_by_supplier_report' __name__ = 'sale_shop.price_list_by_supplier_report'
@classmethod @classmethod
def get_context(cls, records, data): def get_context(cls, records, header, data):
report_context = super(PriceListBySupplierReport, cls).get_context( report_context = super().get_context(records, header, data)
records, data)
pool = Pool() pool = Pool()
Company = pool.get('company.company') Company = pool.get('company.company')
ProductSupplier = pool.get('purchase.product_supplier') ProductSupplier = pool.get('purchase.product_supplier')

View file

@ -7,8 +7,6 @@ from trytond.pyson import Eval
from trytond.pool import PoolMeta, Pool from trytond.pool import PoolMeta, Pool
from trytond.modules.product import price_digits from trytond.modules.product import price_digits
__all__ = ['UpdatePriceProductStart', 'UpdatePriceProduct']
class Product(metaclass=PoolMeta): class Product(metaclass=PoolMeta):
__name__ = 'product.product' __name__ = 'product.product'

103
sale.py
View file

@ -14,11 +14,10 @@ from trytond.report import Report
from trytond.wizard import ( from trytond.wizard import (
Wizard, StateView, StateAction, StateReport, Button Wizard, StateView, StateAction, StateReport, Button
) )
from trytond.i18n import gettext
__all__ = [ from .exceptions import (SaleMissingSequenceError, ShopUserError,
'Sale', 'SaleBySupplierStart', 'SaleBySupplier', 'SaleLine', SaleWriteError)
'PrintSaleBySupplier', from trytond.modules.sale.exceptions import SaleValidationError
]
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
_ZERO = Decimal('0.00') _ZERO = Decimal('0.00')
@ -189,6 +188,7 @@ class PrintSaleBySupplier(Wizard):
shop_id = self.start.shop.id shop_id = self.start.shop.id
shop_name = self.start.shop.name shop_name = self.start.shop.name
data = { data = {
'ids': [],
'company': self.start.company.id, 'company': self.start.company.id,
'start_date': self.start.start_date, 'start_date': self.start.start_date,
'end_date': self.start.end_date, 'end_date': self.start.end_date,
@ -243,8 +243,8 @@ class SaleBySupplier(Report):
return sum([l.quantity for l in lines]), start_date return sum([l.quantity for l in lines]), start_date
@classmethod @classmethod
def get_context(cls, records, data): def get_context(cls, records, header, data):
report_context = super(SaleBySupplier, cls).get_context(records, data) report_context = super().get_context(records, header, data)
pool = Pool() pool = Pool()
Company = pool.get('company.company') Company = pool.get('company.company')
ProductSupplier = pool.get('purchase.product_supplier') ProductSupplier = pool.get('purchase.product_supplier')
@ -412,23 +412,11 @@ class Sale(metaclass=PoolMeta):
cls.currency.states['readonly'] = Eval('state') != 'draft' cls.currency.states['readonly'] = Eval('state') != 'draft'
cls.currency.depends.append('shop') cls.currency.depends.append('shop')
cls._error_messages.update({
'not_sale_shop': (
'Go to user preferences and select a shop ("%s")'),
'no_return_sequence': (
'Return Sale Sequence is missing!'),
'sale_not_shop': (
'Sale have not related a shop'),
'edit_sale_by_shop': ('You cannot edit this order because you '
'do not have permission to edit in this shop.'),
})
@classmethod @classmethod
def __register__(cls, module_name): def __register__(cls, module_name):
TableHandler = backend.get('TableHandler') table_h = cls.__table_handler__(module_name)
table = TableHandler(cls, module_name) # if not table_h.column_exist('shop'):
# if not table.column_exist('shop'): # table_h.add_raw_column(
# table.add_raw_column(
# 'shop', # 'shop',
# cls.shop.sql_type(), # cls.shop.sql_type(),
# cls.shop.sql_format, None, None # cls.shop.sql_format, None, None
@ -440,8 +428,8 @@ class Sale(metaclass=PoolMeta):
# 'UPDATE sale_sale set shop = 1;') # 'UPDATE sale_sale set shop = 1;')
# Migration from 3.8: remove reference constraint # Migration from 3.8: remove reference constraint
if not table.column_exist('number'): if not table_h.column_exist('number'):
table.drop_constraint('reference_uniq') table_h.drop_constraint('reference_uniq')
super(Sale, cls).__register__(module_name) super(Sale, cls).__register__(module_name)
@ -452,38 +440,29 @@ class Sale(metaclass=PoolMeta):
return user.shop.company.id if user.shop else \ return user.shop.company.id if user.shop else \
Transaction().context.get('company') Transaction().context.get('company')
@fields.depends('company')
def on_change_company(self):
User = Pool().get('res.user')
user = User(Transaction().user)
if not user.shop:
super(Sale, self).on_change_company()
else:
self.invoice_method = user.shop.sale_invoice_method
self.shipment_method = user.shop.sale_shipment_method
self.payment_term = user.shop.payment_term.id
@staticmethod @staticmethod
def default_shop(): def default_shop():
User = Pool().get('res.user') User = Pool().get('res.user')
user = User(Transaction().user) user = User(Transaction().user)
return user.shop.id if user.shop else None return user.shop.id if user.shop else None
@staticmethod
def default_invoice_method():
User = Pool().get('res.user')
user = User(Transaction().user)
if not user.shop:
Config = Pool().get('sale.configuration')
config = Config(1)
return config.sale_invoice_method
return user.shop.sale_invoice_method
@staticmethod @staticmethod
def default_description(): def default_description():
config = Pool().get('sale.configuration')(1) config = Pool().get('sale.configuration')(1)
if config.default_description: if config.default_description:
return config.default_description return config.default_description
@staticmethod
def default_shipment_method():
User = Pool().get('res.user')
user = User(Transaction().user)
if not user.shop:
Config = Pool().get('sale.configuration')
config = Config(1)
return config.sale_shipment_method
return user.shop.sale_shipment_method
@staticmethod @staticmethod
def default_warehouse(): def default_warehouse():
User = Pool().get('res.user') User = Pool().get('res.user')
@ -500,12 +479,6 @@ class Sale(metaclass=PoolMeta):
user = User(Transaction().user) user = User(Transaction().user)
return user.shop.price_list.id if user.shop else None return user.shop.price_list.id if user.shop else None
@staticmethod
def default_payment_term():
User = Pool().get('res.user')
user = User(Transaction().user)
return user.shop.payment_term.id if user.shop else None
@staticmethod @staticmethod
def default_shop_address(): def default_shop_address():
User = Pool().get('res.user') User = Pool().get('res.user')
@ -551,7 +524,6 @@ class Sale(metaclass=PoolMeta):
Fill the number field with the sale shop or sale config sequence Fill the number field with the sale shop or sale config sequence
''' '''
pool = Pool() pool = Pool()
Sequence = pool.get('ir.sequence')
Config = pool.get('sale.configuration') Config = pool.get('sale.configuration')
User = Pool().get('res.user') User = Pool().get('res.user')
config = Config(1) config = Config(1)
@ -561,15 +533,16 @@ class Sale(metaclass=PoolMeta):
continue continue
elif sale.shop: elif sale.shop:
if sale.total_amount >= Decimal('0'): if sale.total_amount >= Decimal('0'):
number = Sequence.get_id(sale.shop.sale_sequence.id) number = sale.shop.sale_sequence.get()
else: else:
if not sale.shop.sale_return_sequence: if not sale.shop.sale_return_sequence:
sale.raise_user_error('no_return_sequence') raise SaleMissingSequenceError(
number = Sequence.get_id(sale.shop.sale_return_sequence.id) gettext('sale_shop.msg_no_return_sequence'))
number = sale.shop.sale_return_sequence.get()
elif user.shop: elif user.shop:
number = Sequence.get_id(user.shop.sale_sequence.id) number = user.shop.sale_sequence.get()
else: else:
number = Sequence.get_id(config.sale_sequence.id) number = config.sale_sequence.get()
cls.write([sale], { cls.write([sale], {
'number': number, 'number': number,
}) })
@ -583,9 +556,8 @@ class Sale(metaclass=PoolMeta):
vals = vals.copy() vals = vals.copy()
if not 'shop' in vals: if not 'shop' in vals:
if not user.shop: if not user.shop:
cls.raise_user_error('not_sale_shop', ( raise ShopUserError(
user.rec_name,) gettext('sale_shop.not_sale_shop', s=user.rec_name))
)
vals['shop'] = user.shop.id vals['shop'] = user.shop.id
vlist2.append(vals) vlist2.append(vals)
return super(Sale, cls).create(vlist2) return super(Sale, cls).create(vlist2)
@ -602,11 +574,10 @@ class Sale(metaclass=PoolMeta):
for sales, _ in zip(actions, actions): for sales, _ in zip(actions, actions):
for sale in sales: for sale in sales:
if not sale.shop: if not sale.shop:
print('sale_shop error') raise SaleWriteError(
cls.raise_user_error('sale_not_shop') gettext('sale_shop.msg_sale_not_shop'))
if not sale.shop in user.shops: if not sale.shop in user.shops:
print('sele user error') raise SaleWriteError(gettext('sale_shop.msg_edit_sale_by_shop'))
cls.raise_user_error('edit_sale_by_shop')
super(Sale, cls).write(*args) super(Sale, cls).write(*args)
def _get_invoice_sale(self): def _get_invoice_sale(self):
@ -678,8 +649,8 @@ class SaleShopDetailedReport(Report):
__name__ = 'sale_shop.report_sale_detailed' __name__ = 'sale_shop.report_sale_detailed'
@classmethod @classmethod
def get_context(cls, records, data): def get_context(cls, records, header, data):
report_context = super(SaleShopDetailedReport, cls).get_context(records, data) report_context = super().get_context(records, header, data)
pool = Pool() pool = Pool()
Sale = pool.get('sale.sale') Sale = pool.get('sale.sale')
@ -719,7 +690,7 @@ class SaleShopDetailedReport(Report):
# amount_w_tax = [] # amount_w_tax = []
for line in start_lines: for line in start_lines:
if line.type == 'line' and not line.product: if line.type == 'line' and not line.product:
Sale.raise_user_error('sale_not_product', line.sale.number) raise SaleValidationError(gettext('sale_shop.msg_sale_not_product', s=line.sale.number))
is_invoiced = False is_invoiced = False
if line.sale.invoices: if line.sale.invoices:

View file

@ -52,6 +52,7 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
</record> </record>
<record model="ir.rule.group" id="rule_group_sale"> <record model="ir.rule.group" id="rule_group_sale">
<field name="name">Users in Shops</field>
<field name="model" search="[('model', '=', 'sale.sale')]"/> <field name="model" search="[('model', '=', 'sale.sale')]"/>
<field name="global_p" eval="True"/> <field name="global_p" eval="True"/>
</record> </record>

12
shop.py
View file

@ -2,13 +2,11 @@
# The COPYRIGHT file at the top level of this repository contains # The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms. # the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields from trytond.model import ModelView, ModelSQL, fields
from trytond.pyson import Eval, Bool from trytond.pyson import Eval, Bool, Id
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.pool import Pool from trytond.pool import Pool
from trytond import backend from trytond import backend
__all__ = ['SaleShop', 'SaleShopResUser']
class SaleShop(ModelSQL, ModelView): class SaleShop(ModelSQL, ModelView):
'Sale Shop' 'Sale Shop'
@ -29,7 +27,7 @@ class SaleShop(ModelSQL, ModelView):
'Sale Reference Sequence', domain=[ 'Sale Reference Sequence', domain=[
('company', 'in', [Eval('context', {}).get('company', 0), ('company', 'in', [Eval('context', {}).get('company', 0),
None]), None]),
('code', '=', 'sale.sale'), ('sequence_type', '=', Id('sale', 'sequence_type_sale')),
], required=True) ], required=True)
sale_invoice_method = fields.Selection([ sale_invoice_method = fields.Selection([
('manual', 'Manual'), ('manual', 'Manual'),
@ -56,7 +54,7 @@ class SaleShop(ModelSQL, ModelView):
'Sale Return Sequence', domain=[ 'Sale Return Sequence', domain=[
('company', 'in', ('company', 'in',
[Eval('context', {}).get('company', -1), None]), [Eval('context', {}).get('company', -1), None]),
('code', '=', 'sale.sale'), ('sequence_type', '=', Id('sale', 'sequence_type_sale')),
], required=True) ], required=True)
salesmans = fields.Many2Many('sale.shop.company_employee', 'shop', salesmans = fields.Many2Many('sale.shop.company_employee', 'shop',
'salesman', 'Salesmans') 'salesman', 'Salesmans')
@ -70,15 +68,13 @@ class SaleShop(ModelSQL, ModelView):
@classmethod @classmethod
def __register__(cls, module_name): def __register__(cls, module_name):
pool = Pool() pool = Pool()
TableHandler = backend.get('TableHandler')
Company = pool.get('company.company') Company = pool.get('company.company')
shop_table = cls.__table__() shop_table = cls.__table__()
company_table = Company.__table__() company_table = Company.__table__()
super(SaleShop, cls).__register__(module_name) super(SaleShop, cls).__register__(module_name)
cursor = Transaction().connection.cursor() cursor = Transaction().connection.cursor()
is_sqlite = 'backend.sqlite.table.TableHandler' in str(TableHandler) if backend.name != 'sqlite':
if not is_sqlite:
# SQLite doesn't support this query as it generates and update # SQLite doesn't support this query as it generates and update
# with an alias (AS) which is not valid on SQLite # with an alias (AS) which is not valid on SQLite
query = shop_table.update(columns=[shop_table.currency], query = shop_table.update(columns=[shop_table.currency],

View file

@ -6,8 +6,6 @@ from trytond.model import Workflow, ModelView, ModelSQL, fields
from trytond.pyson import Eval from trytond.pyson import Eval
from trytond.transaction import Transaction from trytond.transaction import Transaction
__all__ = ['SaleSource']
STATES = { STATES = {
'readonly': (Eval('state') != 'draft') 'readonly': (Eval('state') != 'draft')
} }

View file

@ -5,8 +5,6 @@ from trytond.model import fields
from trytond.pool import Pool, PoolMeta from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval from trytond.pyson import Eval
__all__ = ['ShipmentOut', 'ShipmentOutReturn']
class ShipmentOut(metaclass=PoolMeta): class ShipmentOut(metaclass=PoolMeta):
__name__ = 'stock.shipment.out' __name__ = 'stock.shipment.out'

View file

@ -1,5 +1,5 @@
[tryton] [tryton]
version=5.0.6 version=6.0.0
depends: depends:
ir ir
company company

View file

@ -5,8 +5,6 @@ from trytond.model import fields
from trytond.pyson import Eval from trytond.pyson import Eval
from trytond.pool import PoolMeta from trytond.pool import PoolMeta
__all__ = ['User']
class User(metaclass=PoolMeta): class User(metaclass=PoolMeta):
__name__ = "res.user" __name__ = "res.user"