Compare commits

..
19 Commits
Author SHA1 Message Date
pvincent 59b7c48a89 tagged as 1.8.0 2021-08-25 22:23:45 +04:00
pvincent d13c85be61 force semver 2021-08-25 22:23:28 +04:00
pvincent 2714f44b44 README 2021-08-25 22:21:59 +04:00
pvincent 04cb4343ad semver 2021-08-25 22:20:29 +04:00
pvincent e94c4eae67 App.log for DEBUG 2021-08-25 22:17:03 +04:00
pvincent 47abd95962 tagged as 1.7.3 2021-08-25 19:23:35 +04:00
pvincent c346584d46 change readme 2021-08-25 19:23:20 +04:00
cagettepei.lxd bbeea934e4 tagged as 1.7.2 2021-08-25 19:10:48 +04:00
cagettepei.lxd 3c8a2507d9 no package-lock.json 2021-08-25 19:10:35 +04:00
cagettepei.lxd 6c0e632ef2 tagged as 1.7.1 2021-08-25 19:06:37 +04:00
cagettepei.lxd f94e005a91 fix Makefile 2021-08-25 19:06:24 +04:00
cagettepei.lxd 15f89039b3 tagged as 1.7.0 2021-08-25 19:01:52 +04:00
cagettepei.lxd 0d3a32a018 no more cagette-pro and tests 2021-08-25 19:01:17 +04:00
pvincent 2641e70eaf update README 2021-08-12 21:59:43 +04:00
pvincent 0ebb698c54 tagged as 1.6.0 2021-08-12 21:55:17 +04:00
pvincent 3621289fee install from scratch 2021-08-12 21:55:06 +04:00
pvincent 544db390ef install from scratch 2021-08-12 21:54:14 +04:00
pvincent f357d716b7 tagged as 1.5.4 2021-08-12 21:34:28 +04:00
pvincent a49bee1a52 fix: gitignore 2021-08-12 21:34:20 +04:00
21 changed files with 808 additions and 8577 deletions
+1 -1
View File
@@ -1,6 +1,7 @@
*.n *.n
*.php *.php
config.xml config.xml
package-lock.json
www/plugin/* www/plugin/*
tmp/* tmp/*
*node_modules* *node_modules*
@@ -34,4 +35,3 @@ www/css/.sass-cache
www/css/*.css www/css/*.css
!www/css/bootstrap.min.css !www/css/bootstrap.min.css
+1 -1
View File
@@ -1 +1 @@
1.5.3 1.8.0
+1 -21
View File
@@ -26,12 +26,6 @@ install_dev:
#template tools #template tools
haxelib run templo haxelib run templo
sudo mv temploc2 /usr/bin sudo mv temploc2 /usr/bin
#extra plugins
@if [ $(PLUGINS) = 1 ]; then \
haxelib git cagette-pro git@bitbucket.org:bubar/cagette-pro.git; \
haxelib git cagette-hosted git@bitbucket.org:bubar/cagette-hosted.git; \
haxelib git cagette-wholesale-order git@github.com:bablukid/cagette-wholesale-order.git; \
fi
#install npm dependencies #install npm dependencies
npm install npm install
npm run libs:dev npm run libs:dev
@@ -80,22 +74,8 @@ templates:
@make LANG=fr ctemplates @make LANG=fr ctemplates
msgfmt www/lang/texts_fr.po -o www/lang/texts_fr.mo msgfmt www/lang/texts_fr.po -o www/lang/texts_fr.mo
chown www-data:www-data -R www chown www-data:www-data -R www
chown www-data:www-data -R lang
ctemplates: ctemplates:
# (cd lang/$(LANG)/tpl; temploc2 -macros macros.mtt -output ../tmp/ *.mtt */*.mtt */*/*.mtt */*/*/*.mtt */*/*/*/*.mtt)
(cd lang/$(LANG)/tpl; temploc2 -macros macros.mtt -output ../tmp/ *.mtt */*.mtt */*/*.mtt) (cd lang/$(LANG)/tpl; temploc2 -macros macros.mtt -output ../tmp/ *.mtt */*.mtt */*/*.mtt)
#Compile and run unit tests
tests:
@if [ $(PLUGINS) = 1 ]; then \
haxe testsPlugins.hxml; \
else \
haxe tests.hxml; \
fi
@docker-compose run --workdir="/var/www/www" neko neko tests.n mysql://root:root@mysql/tests
cp_plugin:
cp -R .haxelib/cagette-hosted/git/tpl/* lang/master/tpl/plugin/hosted/
cp -R .haxelib/cagette-pro/git/tpl/* lang/master/tpl/plugin/pro/
cp -R .haxelib/cagette-wholesale-order/git/tpl/* lang/master/tpl/plugin/who/
+167 -1
View File
@@ -1,8 +1,174 @@
# Cagette péi CAGETTE PEI
===========
Fourche du logiciel [Cagette.net](https://github.com/CagetteNet) à partir de la version 0.9.2 Novembre 2018 Fourche du logiciel [Cagette.net](https://github.com/CagetteNet) à partir de la version 0.9.2 Novembre 2018
Certaines portions du code source de Cagette.net n'étant plus disponibles en téléchargement, Certaines portions du code source de Cagette.net n'étant plus disponibles en téléchargement,
j'ai repris sur la base d'un existant pour adapter au marché local réunionnais et leurs AMAPéi. j'ai repris sur la base d'un existant pour adapter au marché local réunionnais et leurs AMAPéi.
## INSTALL FROM SCRATCH (debian-buster)
* apt install -y curl
* curl -L https://deb.nodesource.com/setup_8.x | bash -
* apt install -y nodejs=8.17.0-1nodesource1
* apt install -y sudo haxe apache2 make git imagemagick gettext libapache2-mod-neko mariadb-server
* mysql -u root <<EOF
CREATE DATABASE cagettepei;
GRANT ALL ON cagettepei.* TO 'cagettepei'@'%' IDENTIFIED BY 'cagettepei';
EOF
* cd /var/www
* git clone https://git.artcode.re/cagetters/cagettepei.git
* cd cagettepei
* make install ENV=dev # first time
* make compile # classes
* make templates # templates + i18n
* vim /etc/apache2/sites-available/cagettepei.conf
```
<VirtualHost *:80>
ServerName cagettepei
DirectoryIndex index.n
DocumentRoot /var/www/cagettepei/www/
</VirtualHost>
```
* sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
* a2dissite 000-default.conf
* a2ensite cagettepei.conf
* a2enmod neko rewrite
* systemctl restart apache2
## CONFIGURATION
* cd /var/www/cagettepei
* vim config.xml
```
<config
host="<DOMAIN.TLD>"
key="<SECRET_PHRASE>"
name = "CagettePéi"
default_email = "<EMAIL>"
webmaster_email = "<EMAIL>"
database="mysql://cagettepei:cagettepei@localhost/cagettepei"
smtp_host="localhost"
smtp_port="25"
smtp_user=""
smtp_pass=""
lang="fr"
langs="fr"
langnames="Français"
maintain="0"
debug="0"
sqllog="0"
cache="1"
cachetpl="0"
/>
```
ADMIN RESET PASSWORD
--------------------
go to http://localhost for ERROR + table regeneration, then
* cd /var/www/cagettepei
* SECRET=$(grep key= config.xml | cut -d= -f2 | cut -d'"' -f2)
* echo "insert into User values (1,'fr',MD5('${SECRET}cagettepei'),1,'Administrateur','Cagette Péi', 'admin', null, null, null, null, null, null, null, null, null, now(), now(),6,null, null)" | mysql -h localhost -u cagettepei -pcagettepei cagettepei
then, connect with admin / cagettepei
### change admin password
* echo "update User set pass=MD5('${SECRET}cagettepei') where id=1" | mysql -h localhost -u cagettepei -pcagettepei cagettepei
SYSTEMD-TIMERS
--------------
* vim /var/www/cagettepei-batch
```
#!/bin/bash
case $1 in
minute);;
daily);;
*) echo "expected [minute|daily]" && exit 1;;
esac
SELECTOR=$1
for i in /var/www/cagettepei-* ; do
if [[ -d $i ]]; then
cd $i/www
echo "cron-$SELECTOR in: $i"
neko index.n cron/$SELECTOR
echo
fi
done
```
* chmod +x /var/www/cagettepei-batch
* vim /etc/systemd/system/cagettepei-batch-minute.service
```
[Unit]
Description=Run batch cagettepei every minute
[Service]
User=www-data
SyslogIdentifier=cagettepei
ExecStart=/var/www/cagettepei-batch minute
[Install]
WantedBy=multi-user.target
```
* vim /etc/systemd/system/cagettepei-batch-day.service
```
[Unit]
Description=Run batch cagettepei every day
[Service]
User=www-data
SyslogIdentifier=cagettepei
ExecStart=/var/www/cagettepei-batch daily
[Install]
WantedBy=multi-user.target
```
* vim /etc/systemd/system/cagettepei-batch-minute.timer
```
[Unit]
Description=Timer for batch cagettepei every minute
Requires=apache2.service
[Timer]
OnCalendar=minutely
Unit=cagettepei-batch-minute.service
[Install]
WantedBy=timers.target
```
* vim /etc/systemd/system/cagettepei-batch-day.timer
```
[Unit]
Description=Timer for batch cagettepei every day
Requires=apache2.service
[Timer]
OnCalendar=daily
Unit=cagettepei-batch-day.service
[Install]
WantedBy=timers.target
```
* systemctl daemon-reload
* systemctl edit apache2 # bind the 2 timers to apache2 cagette
```
[Unit]
BindsTo = cagettepei-batch-minute.timer cagettepei-batch-day.timer
```
* systemctl enable cagettepei-batch-minute.timer cagettepei-batch-day.timer
* systemctl start cagettepei-batch-minute.timer cagettepei-batch-day.timer
-26
View File
@@ -1,26 +0,0 @@
-lib templo
-lib hxevents
-lib thx.semver
-lib thx.csv
-lib datetime
-lib hscript
-lib smtpmailer
-lib tink_json
-lib sugoi:git:https://github.com/bablukid/sugoi#master
-lib record-macros:git:https://github.com/HaxeFoundation/record-macros#master
-lib dbadmin:git:https://github.com/ncannasse/dbadmin.git#master
-lib cagette-pro:git:https://bubar@bitbucket.org/bubar/cagette-pro.git#master
-lib cagette-hosted:git:https://bubar@bitbucket.org/bubar/cagette-hosted.git#master
-lib cagette-wholesale-order:git:https://github.com/bablukid/cagette-wholesale-order.git#master
-cp common
-cp src
-cp lang/master/tpl
-D plugins
-neko www/index.n
-main App
-76
View File
@@ -1,76 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<project version="2">
<!-- Output SWF options -->
<output>
<movie outputType="Application" />
<movie input="" />
<movie path="www\index.n" />
<movie fps="30" />
<movie width="800" />
<movie height="600" />
<movie version="0" />
<movie minorVersion="0" />
<movie platform="Neko" />
<movie background="#FFFFFF" />
</output>
<!-- Other classes to be compiled into your SWF -->
<classpaths>
<class path="common" />
<class path="src" />
<class path="lang\master\tpl" />
</classpaths>
<!-- Build options -->
<build>
<option directives="plugins" />
<option flashStrict="False" />
<option noInlineOnDebug="False" />
<option mainClass="App" />
<option enabledebug="False" />
<option additional="" />
</build>
<!-- haxelib libraries -->
<haxelib>
<library name="templo" />
<library name="thx.semver" />
<library name="thx.csv" />
<library name="hxevents" />
<library name="hscript" />
<library name="record-macros" />
<library name="smtpmailer" />
<library name="datetime" />
<library name="sugoi:git:https://github.com/bablukid/sugoi#i18n" />
<library name="record-macros:git:https://github.com/HaxeFoundation/record-macros#maste" />
<library name="dbadmin:git:https://github.com/ncannasse/dbadmin.git#master" />
<library name="cagette-pro:git:https://bubar@bitbucket.org/bubar/cagette-pro.git#master" />
<library name="cagette-connector:git:https://bubar@bitbucket.org/bubar/cagette-connector.git#master" />
<library name="cagette-wholesale-order:git:https://bubar@bitbucket.org/bubar/cagette-wholesale-order.git#master" />
<library name="cagette-hosted:git:https://bubar@bitbucket.org/bubar/cagette-hosted.git#master" />
</haxelib>
<!-- Class files to compile (other referenced classes will automatically be included) -->
<compileTargets>
<!-- example: <compile path="..." /> -->
</compileTargets>
<!-- Paths to exclude from the Project Explorer tree -->
<hiddenPaths>
<hidden path="project.hxml" />
<hidden path="lang\fr\tmp" />
<hidden path="preLaunch" />
<hidden path="art" />
<hidden path="www\file" />
<hidden path="config.tpl.xml" />
<hidden path="clearFileCache.bat" />
<hidden path="obj" />
</hiddenPaths>
<!-- Executed before build -->
<preBuildCommand />
<!-- Executed after build -->
<postBuildCommand alwaysRun="False" />
<!-- Other project options -->
<options>
<option showHiddenPaths="True" />
<option testMovie="Custom" />
<option testMovieCommand="" />
</options>
<!-- Plugin storage -->
<storage />
</project>
-17
View File
@@ -1,17 +0,0 @@
-dce no
-cp common
-cp js
-lib sugoi:git:https://github.com/bablukid/sugoi#i18n
-lib hxleaflet:git:https://github.com/bablukid/hxleaflet
-lib cagette-hosted
-lib react
-lib react-router-4
-lib modular
-lib tink_json
-D plugins
-D no-deprecation-warnings
-main App
-js www/js/app.js
-6187
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -47,5 +47,5 @@
"bugs": { "bugs": {
"url": "https://github.com/bablukid/cagette/issues" "url": "https://github.com/bablukid/cagette/issues"
}, },
"version": "1.5.3" "version": "1.8.0"
} }
+108 -116
View File
@@ -1,110 +1,109 @@
import db.User; import db.User;
import thx.semver.Version; import thx.semver.Version;
import Common; import Common;
class App extends sugoi.BaseApp {
public static var current : App = null; class App extends sugoi.BaseApp {
public static var t : sugoi.i18n.translator.ITranslator; public static var current:App = null;
public static var t:sugoi.i18n.translator.ITranslator;
public static var config = sugoi.BaseApp.config; public static var config = sugoi.BaseApp.config;
public var eventDispatcher :hxevents.Dispatcher<Event>; public var eventDispatcher:hxevents.Dispatcher<Event>;
public var plugins : Array<sugoi.plugin.IPlugIn>; public var plugins:Array<sugoi.plugin.IPlugIn>;
/** /**
* Version management * Version management
* @doc https://github.com/fponticelli/thx.semver * @doc https://github.com/fponticelli/thx.semver
*/ */
//public static var VERSION = ([0,9,2] : Version).withPre("july"); // public static var VERSION = ([0,9,2] : Version).withPre("july");
//public static var VERSION = ([0,9,2] : Version).withPre(MyMacros.getGitShortSHA(), MyMacros.getGitCommitDate()); // public static var VERSION = ([0,9,2] : Version).withPre(MyMacros.getGitShortSHA(), MyMacros.getGitCommitDate());
public static var VERSION = "cagette-péi " + MyMacros.getGitCommitDate(); public static var VERSION = "cagette-péi " + MyMacros.getGitCommitDate();
public function new(){ public function new() {
super(); super();
} }
public static function main() { public static function main() {
App.t = sugoi.form.Form.translator = new sugoi.i18n.translator.TMap(getTranslationArray(), "fr"); App.t = sugoi.form.Form.translator = new sugoi.i18n.translator.TMap(getTranslationArray(), "fr");
sugoi.BaseApp.main(); sugoi.BaseApp.main();
} }
/** /**
* Init plugins and event dispatcher just before launching the app * Init plugins and event dispatcher just before launching the app
*/ */
override public function mainLoop() { override public function mainLoop() {
eventDispatcher = new hxevents.Dispatcher<Event>(); eventDispatcher = new hxevents.Dispatcher<Event>();
plugins = []; plugins = [];
//internal plugins // internal plugins
plugins.push(new plugin.Tutorial()); plugins.push(new plugin.Tutorial());
//optionnal plugins // optionnal plugins
#if plugins #if plugins
plugins.push( new hosted.HostedPlugIn() ); plugins.push(new hosted.HostedPlugIn());
plugins.push( new pro.ProPlugIn() ); plugins.push(new pro.ProPlugIn());
plugins.push( new connector.ConnectorPlugIn() ); plugins.push(new connector.ConnectorPlugIn());
plugins.push( new pro.LemonwayEC() ); plugins.push(new pro.LemonwayEC());
plugins.push( new who.WhoPlugIn() ); plugins.push(new who.WhoPlugIn());
#end #end
super.mainLoop(); super.mainLoop();
} }
public function getCurrentGroup(){ public function getCurrentGroup() {
if (session == null) return null; if (session == null)
if (session.data == null ) return null; return null;
if (session.data == null)
return null;
var a = session.data.amapId; var a = session.data.amapId;
if (a == null) { if (a == null) {
return null; return null;
}else { } else {
return db.Amap.manager.get(a,false); return db.Amap.manager.get(a, false);
} }
} }
override function beforeDispatch() { override function beforeDispatch() {
// send "current page" event
//send "current page" event event(Page(this.uri));
event( Page(this.uri) );
super.beforeDispatch(); super.beforeDispatch();
} }
public function getPlugin(name:String):sugoi.plugin.IPlugIn { public function getPlugin(name:String):sugoi.plugin.IPlugIn {
for (p in plugins) { for (p in plugins) {
if (p.getName() == name) return p; if (p.getName() == name)
return p;
} }
return null; return null;
} }
public static function log(t:Dynamic) { public static function log(t:Dynamic, ?infos:haxe.PosInfos) {
if(App.config.DEBUG) { if (App.config.DEBUG) {
neko.Web.logMessage(Std.string(t)); //write in Apache error log // neko.Web.logMessage(Std.string(t)); // write in Apache error log
#if weblog neko.Web.logMessage('[${infos.fileName}:${infos.lineNumber} ${infos.className}#${infos.methodName}] ' + Std.string(t));
Weblog.log(t); //write en Weblog console (https://lib.haxe.org/p/weblog/)
#end
} }
} }
public function event(e:Event) { public function event(e:Event) {
if(e==null) return null; if (e == null)
return null;
this.eventDispatcher.dispatch(e); this.eventDispatcher.dispatch(e);
return e; return e;
} }
/** /**
* Translate DB objects fields in forms * Translate DB objects fields in forms
*/ */
public static function getTranslationArray() { public static function getTranslationArray() {
//var t = sugoi.i18n.Locale.texts; // var t = sugoi.i18n.Locale.texts;
var out = new Map<String,String>(); var out = new Map<String, String>();
//out.set("firstName", t._("First name") ); // out.set("firstName", t._("First name") );
//out.set("lastName", t._("Last name")); // out.set("lastName", t._("Last name"));
out.set("firstName2", "Prénom du conjoint"); out.set("firstName2", "Prénom du conjoint");
out.set("lastName2", "Nom du conjoint"); out.set("lastName2", "Nom du conjoint");
out.set("email2", "e-mail du conjoint"); out.set("email2", "e-mail du conjoint");
//out.set("pass", t._("Password") ); // out.set("pass", t._("Password") );
//out.set("address1", t._("address") ); // out.set("address1", t._("address") );
//out.set("address2", t._("address") ); // out.set("address2", t._("address") );
out.set("zipCode", "code postal"); out.set("zipCode", "code postal");
out.set("city", "commune"); out.set("city", "commune");
out.set("phone", "téléphone"); out.set("phone", "téléphone");
@@ -123,24 +122,24 @@ class App extends sugoi.BaseApp {
out.set("txtHome", "Texte en page d'accueil pour les adhérents connectés"); out.set("txtHome", "Texte en page d'accueil pour les adhérents connectés");
out.set("txtDistrib", "Texte à faire figurer sur les listes d'émargement lors des distributions"); out.set("txtDistrib", "Texte à faire figurer sur les listes d'émargement lors des distributions");
out.set("extUrl", "URL du site du groupe."); out.set("extUrl", "URL du site du groupe.");
out.set("distributor1", "Distributeur 1"); out.set("distributor1", "Distributeur 1");
out.set("distributor2", "Distributeur 2"); out.set("distributor2", "Distributeur 2");
out.set("distributor3", "Distributeur 3"); out.set("distributor3", "Distributeur 3");
out.set("distributor4", "Distributeur 4"); out.set("distributor4", "Distributeur 4");
out.set("distributorNum", "Nbre de distributeurs nécessaires (de 0 à 4)"); out.set("distributorNum", "Nbre de distributeurs nécessaires (de 0 à 4)");
out.set("startDate", "Date de début"); out.set("startDate", "Date de début");
out.set("endDate", "Date de fin"); out.set("endDate", "Date de fin");
out.set("orderStartDate", "Date ouverture des commandes"); out.set("orderStartDate", "Date ouverture des commandes");
out.set("orderEndDate", "Date fermeture des commandes"); out.set("orderEndDate", "Date fermeture des commandes");
out.set("openingHour", "Heure d'ouverture"); out.set("openingHour", "Heure d'ouverture");
out.set("closingHour", "Heure de fermeture"); out.set("closingHour", "Heure de fermeture");
out.set("date", "Date de distribution"); out.set("date", "Date de distribution");
out.set("active", "actif"); out.set("active", "actif");
out.set("contact", "Reponsable"); out.set("contact", "Reponsable");
out.set("vendor", "Producteur"); out.set("vendor", "Producteur");
out.set("text", "Texte"); out.set("text", "Texte");
@@ -170,7 +169,7 @@ class App extends sugoi.BaseApp {
out.set("pname", "Produit"); out.set("pname", "Produit");
out.set("organic", "Agriculture biologique"); out.set("organic", "Agriculture biologique");
out.set("hasFloatQt", "Autoriser quantités \"à virgule\""); out.set("hasFloatQt", "Autoriser quantités \"à virgule\"");
out.set("membershipRenewalDate", "Adhésions : Date de renouvellement"); out.set("membershipRenewalDate", "Adhésions : Date de renouvellement");
out.set("membershipPrice", "Adhésions : Coût de l'adhésion"); out.set("membershipPrice", "Adhésions : Coût de l'adhésion");
out.set("UsersCanOrder", "Les adhérents peuvent saisir leur commande en ligne"); out.set("UsersCanOrder", "Les adhérents peuvent saisir leur commande en ligne");
@@ -193,12 +192,12 @@ class App extends sugoi.BaseApp {
out.set("ref", "Référence"); out.set("ref", "Référence");
out.set("linkText", "Intitulé du lien"); out.set("linkText", "Intitulé du lien");
out.set("linkUrl", "URL du lien"); out.set("linkUrl", "URL du lien");
out.set("Amap", "AMAP"); out.set("Amap", "AMAP");
out.set("GroupedOrders", "Groupement d'achat"); out.set("GroupedOrders", "Groupement d'achat");
out.set("ProducerDrive", "Collectif de producteurs"); out.set("ProducerDrive", "Collectif de producteurs");
out.set("FarmShop", "Vente à la ferme"); out.set("FarmShop", "Vente à la ferme");
out.set("regOption", "Inscription de nouveaux adhérents"); out.set("regOption", "Inscription de nouveaux adhérents");
out.set("Closed", "Fermé : Le coordinateur ajoute les nouveaux adhérents"); out.set("Closed", "Fermé : Le coordinateur ajoute les nouveaux adhérents");
out.set("WaitingList", "Liste d'attente"); out.set("WaitingList", "Liste d'attente");
@@ -206,102 +205,95 @@ class App extends sugoi.BaseApp {
out.set("Full", "Complet : Le groupe n'accepte plus de nouveaux adhérents"); out.set("Full", "Complet : Le groupe n'accepte plus de nouveaux adhérents");
out.set("percent", "Pourcentage"); out.set("percent", "Pourcentage");
out.set("pinned", "Mets en avant les produits"); out.set("pinned", "Mets en avant les produits");
out.set("CagetteNetwork", "Me lister dans l'annuaire des groupes Cagette.net"); out.set("CagetteNetwork", "Me lister dans l'annuaire des groupes Cagette.net");
out.set("unitType", "Unité"); out.set("unitType", "Unité");
out.set("qt", "Quantité"); out.set("qt", "Quantité");
out.set("Unit", "Pièce"); out.set("Unit", "Pièce");
out.set("Kilogram", "Kilogrammes"); out.set("Kilogram", "Kilogrammes");
out.set("Gram", "Grammes"); out.set("Gram", "Grammes");
out.set("Litre", "Litres"); out.set("Litre", "Litres");
out.set("htPrice", "Prix H.T"); out.set("htPrice", "Prix H.T");
out.set("amount", "Montant"); out.set("amount", "Montant");
out.set("HasPayments", "Gestion des paiements"); out.set("HasPayments", "Gestion des paiements");
out.set("byMember", "Par adhérent"); out.set("byMember", "Par adhérent");
out.set("byProduct", "Par produit"); out.set("byProduct", "Par produit");
out.set("variablePrice", "Variable price based on weight"); out.set("variablePrice", "Variable price based on weight");
return out; return out;
} }
public function populateAmapMembers() { public function populateAmapMembers() {
return user.amap.getMembersFormElementData(); return user.amap.getMembersFormElementData();
} }
public static function getMailer():sugoi.mail.IMailer {
var mailer : sugoi.mail.IMailer = new sugoi.mail.BufferedMailer();
if(App.config.DEBUG){
//Dev env : emails are written to tmp folder public static function getMailer():sugoi.mail.IMailer {
var mailer:sugoi.mail.IMailer = new sugoi.mail.BufferedMailer();
if (App.config.DEBUG) {
// Dev env : emails are written to tmp folder
mailer = new sugoi.mail.DebugMailer(); mailer = new sugoi.mail.DebugMailer();
}else{ } else {
if (sugoi.db.Variable.get("mailer") == null) {
if (sugoi.db.Variable.get("mailer") == null){
var msg = sugoi.i18n.Locale.texts._("Please configure the email settings in a <href='/admin/emails'>this section</a>"); var msg = sugoi.i18n.Locale.texts._("Please configure the email settings in a <href='/admin/emails'>this section</a>");
throw sugoi.ControllerAction.ErrorAction("/",msg); throw sugoi.ControllerAction.ErrorAction("/", msg);
} }
if (sugoi.db.Variable.get("mailer") == "mandrill"){ if (sugoi.db.Variable.get("mailer") == "mandrill") {
//Buffered emails with Mandrill // Buffered emails with Mandrill
untyped mailer.defineFinalMailer("mandrill"); untyped mailer.defineFinalMailer("mandrill");
}else{ } else {
//Buffered emails with SMTP // Buffered emails with SMTP
untyped mailer.defineFinalMailer("smtp"); untyped mailer.defineFinalMailer("smtp");
} }
} }
return mailer; return mailer;
} }
/** /**
* Send an email * Send an email
*/ */
public static function sendMail(m:sugoi.mail.Mail, ?group:db.Amap, ?listId:String, ?sender:db.User){ public static function sendMail(m:sugoi.mail.Mail, ?group:db.Amap, ?listId:String, ?sender:db.User) {
if (group == null)
if (group == null) group = App.current.user == null ? null:App.current.user.getAmap(); group = App.current.user == null ? null : App.current.user.getAmap();
current.event(SendEmail(m));
var params = group==null ? null : {remoteId:group.id};
getMailer().send(m,params,function(o){}); current.event(SendEmail(m));
var params = group == null ? null : {remoteId: group.id};
getMailer().send(m, params, function(o) {});
} }
public static function quickMail(to:String, subject:String, html:String,?group:db.Amap){ public static function quickMail(to:String, subject:String, html:String, ?group:db.Amap) {
var e = new sugoi.mail.Mail(); var e = new sugoi.mail.Mail();
e.setSubject(subject); e.setSubject(subject);
e.setRecipient(to); e.setRecipient(to);
e.setSender(App.config.get("default_email"),"Cagette.net"); e.setSender(App.config.get("default_email"), "Cagette.net");
var html = App.current.processTemplate("mail/message.mtt", {text:html,group:group}); var html = App.current.processTemplate("mail/message.mtt", {text: html, group: group});
e.setHtmlBody(html); e.setHtmlBody(html);
App.sendMail(e); App.sendMail(e);
} }
/** /**
* process a template and returns the generated string * process a template and returns the generated string
* @param tpl * @param tpl
* @param ctx * @param ctx
*/ */
public function processTemplate(tpl:String, ctx:Dynamic):String { public function processTemplate(tpl:String, ctx:Dynamic):String {
Reflect.setField(ctx, 'HOST', App.config.HOST); Reflect.setField(ctx, 'HOST', App.config.HOST);
Reflect.setField(ctx, 'hDate', App.current.view.hDate); Reflect.setField(ctx, 'hDate', App.current.view.hDate);
//i18n functions // i18n functions
ctx._ = App.current.view._; ctx._ = App.current.view._;
ctx.__ = App.current.view.__; ctx.__ = App.current.view.__;
var tpl = loadTemplate(tpl); var tpl = loadTemplate(tpl);
var html = tpl.execute(ctx); var html = tpl.execute(ctx);
#if php #if php
if ( html.substr(0, 4) == "null") html = html.substr(4); if (html.substr(0, 4) == "null")
html = html.substr(4);
#end #end
return html; return html;
} }
} }
File diff suppressed because it is too large Load Diff
-299
View File
@@ -1,299 +0,0 @@
package test;
/**
* Test distribution creation
*
* @author web-wizard
*/
class TestDistributions extends haxe.unit.TestCase
{
public function new(){
super();
}
/**
*
*/
override function setup(){
TestSuite.initDB();
TestSuite.initDatas();
}
/**
* Check that we can add a distribution outside existing time range for a specific contract and place
* Check that we can't add a distribution overlapping with existing distribution for a specific contract and place
*/
function testOverlapping() {
var existingDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE;
var e1 = null;
try {
var distrib1 = service.DistributionService.create(existingDistrib.contract,new Date(2018, 5, 1, 18, 0, 0),new Date(2018, 5, 1, 18, 30, 0),
existingDistrib.place.id,null,null,null,null,new Date(2018, 4, 1, 18, 0, 0),new Date(2018, 4, 30, 18, 30, 0));
}
catch(x:tink.core.Error) {
e1 = x;
}
assertEquals(e1, null);
//existingDistrib.date <= distrib2.date && existingDistrib.end >= distrib2.date
var e2 = null;
try {
var distrib2 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 19, 30, 0),new Date(2017, 5, 1, 20, 30, 0),
existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0));
}
catch(x:tink.core.Error) {
e2 = x;
}
assertEquals(e2.message, "There is already a distribution at this place overlapping with the time range you've selected.");
//existingDistrib.date <= distrib3.end && existingDistrib.end >= distrib3.end
var e3 = null;
try{
var distrib3 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 17, 30, 0),new Date(2017, 5, 1, 19, 30, 0),
existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0));
}
catch(x:tink.core.Error){
e3 = x;
}
assertEquals(e3.message, "There is already a distribution at this place overlapping with the time range you've selected.");
//existingDistrib.date >= distrib4.date && existingDistrib.end <= distrib4.end
var e4 = null;
try{
var distrib4 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 17, 30, 0),new Date(2017, 5, 1, 21, 30, 0),
existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0));
}
catch(x:tink.core.Error){
e4 = x;
}
assertEquals(e4.message, "There is already a distribution at this place overlapping with the time range you've selected.");
//existingDistrib.date > distrib5.end
var e5 = null;
try{
var distrib5 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 5, 1, 17, 30, 0),new Date(2017, 5, 1, 18, 59, 0),
existingDistrib.place.id,null,null,null,null,new Date(2017, 4, 1, 18, 0, 0),new Date(2017, 4, 30, 18, 30, 0));
}
catch(x:tink.core.Error){
e5 = x;
}
assertEquals(e5, null);
//existingDistrib.date > distrib6.end
var e6 = null;
try{
var distrib6 = service.DistributionService.create(existingDistrib.contract,new Date(2017, 3, 1, 17, 30, 0),new Date(2017, 3, 1, 18, 59, 0),
existingDistrib.place.id,null,null,null,null,new Date(2017, 2, 1, 18, 0, 0),new Date(2017, 3, 30, 18, 30, 0));
}
catch(x:tink.core.Error){
e6 = x;
}
assertEquals(e6.message, "The distribution start date must be set after the orders end date.");
}
/**
* Check that we can add a distribution outside existing time range for a specific contract and place
* Check that we can't add a distribution overlapping with existing distribution for a specific contract and place
*/
function testEdit() {
//TO DO
assertEquals(true, true);
}
function testCreateCycle() {
TestSuite.CONTRAT_LEGUMES.startDate = new Date(2018, 0, 1, 0, 0, 0);
TestSuite.CONTRAT_LEGUMES.endDate = new Date(2019, 11, 31, 23, 59, 0);
TestSuite.CONTRAT_LEGUMES.update();
var weeklyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,Weekly,new Date(2018, 11, 24, 0, 0, 0),
new Date(2019, 0, 24, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2,
new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id);
var weeklyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == weeklyDistribCycle, false));
assertEquals(weeklyDistribs.length, 5);
assertEquals(weeklyDistribs[0].date.toString(), new Date(2018, 11, 24, 13, 0, 0).toString());
assertEquals(weeklyDistribs[0].end.toString(), new Date(2018, 11, 24, 14, 0, 0).toString());
assertEquals(weeklyDistribs[1].date.toString(), new Date(2018, 11, 31, 13, 0, 0).toString());
assertEquals(weeklyDistribs[1].end.toString(), new Date(2018, 11, 31, 14, 0, 0).toString());
assertEquals(weeklyDistribs[2].date.toString(), new Date(2019, 0, 7, 13, 0, 0).toString());
assertEquals(weeklyDistribs[2].end.toString(), new Date(2019, 0, 7, 14, 0, 0).toString());
assertEquals(weeklyDistribs[3].date.toString(), new Date(2019, 0, 14, 13, 0, 0).toString());
assertEquals(weeklyDistribs[3].end.toString(), new Date(2019, 0, 14, 14, 0, 0).toString());
assertEquals(weeklyDistribs[4].date.toString(), new Date(2019, 0, 21, 13, 0, 0).toString());
assertEquals(weeklyDistribs[4].end.toString(), new Date(2019, 0, 21, 14, 0, 0).toString());
service.DistributionService.deleteCycleDistribs(weeklyDistribCycle);
var monthlyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,Monthly,new Date(2018, 9, 30, 0, 0, 0),
new Date(2019, 2, 31, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2,
new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id);
var monthlyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == monthlyDistribCycle, false));
assertEquals(monthlyDistribs.length, 6);
assertEquals(monthlyDistribs[0].date.toString(), new Date(2018, 9, 30, 13, 0, 0).toString());
assertEquals(monthlyDistribs[0].end.toString(), new Date(2018, 9, 30, 14, 0, 0).toString());
assertEquals(monthlyDistribs[1].date.toString(), new Date(2018, 10, 27, 13, 0, 0).toString());
assertEquals(monthlyDistribs[1].end.toString(), new Date(2018, 10, 27, 14, 0, 0).toString());
assertEquals(monthlyDistribs[2].date.toString(), new Date(2018, 11, 25, 13, 0, 0).toString());
assertEquals(monthlyDistribs[2].end.toString(), new Date(2018, 11, 25, 14, 0, 0).toString());
assertEquals(monthlyDistribs[3].date.toString(), new Date(2019, 0, 29, 13, 0, 0).toString());
assertEquals(monthlyDistribs[3].end.toString(), new Date(2019, 0, 29, 14, 0, 0).toString());
assertEquals(monthlyDistribs[4].date.toString(), new Date(2019, 1, 26, 13, 0, 0).toString());
assertEquals(monthlyDistribs[4].end.toString(), new Date(2019, 1, 26, 14, 0, 0).toString());
assertEquals(monthlyDistribs[5].date.toString(), new Date(2019, 2, 26, 13, 0, 0).toString());
assertEquals(monthlyDistribs[5].end.toString(), new Date(2019, 2, 26, 14, 0, 0).toString());
service.DistributionService.deleteCycleDistribs(monthlyDistribCycle);
var biweeklyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,BiWeekly,new Date(2018, 9, 30, 0, 0, 0),
new Date(2019, 0, 31, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2,
new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id);
var biweeklyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == biweeklyDistribCycle, false));
assertEquals(biweeklyDistribs.length, 7);
assertEquals(biweeklyDistribs[0].date.toString(), new Date(2018, 9, 30, 13, 0, 0).toString());
assertEquals(biweeklyDistribs[0].end.toString(), new Date(2018, 9, 30, 14, 0, 0).toString());
assertEquals(biweeklyDistribs[1].date.toString(), new Date(2018, 10, 13, 13, 0, 0).toString());
assertEquals(biweeklyDistribs[1].end.toString(), new Date(2018, 10, 13, 14, 0, 0).toString());
assertEquals(biweeklyDistribs[2].date.toString(), new Date(2018, 10, 27, 13, 0, 0).toString());
assertEquals(biweeklyDistribs[2].end.toString(), new Date(2018, 10, 27, 14, 0, 0).toString());
assertEquals(biweeklyDistribs[3].date.toString(), new Date(2018, 11, 11, 13, 0, 0).toString());
assertEquals(biweeklyDistribs[3].end.toString(), new Date(2018, 11, 11, 14, 0, 0).toString());
assertEquals(biweeklyDistribs[4].date.toString(), new Date(2018, 11, 25, 13, 0, 0).toString());
assertEquals(biweeklyDistribs[4].end.toString(), new Date(2018, 11, 25, 14, 0, 0).toString());
assertEquals(biweeklyDistribs[5].date.toString(), new Date(2019, 0, 8, 13, 0, 0).toString());
assertEquals(biweeklyDistribs[5].end.toString(), new Date(2019, 0, 8, 14, 0, 0).toString());
assertEquals(biweeklyDistribs[6].date.toString(), new Date(2019, 0, 22, 13, 0, 0).toString());
assertEquals(biweeklyDistribs[6].end.toString(), new Date(2019, 0, 22, 14, 0, 0).toString());
service.DistributionService.deleteCycleDistribs(biweeklyDistribCycle);
var triweeklyDistribCycle = service.DistributionService.createCycle(TestSuite.CONTRAT_LEGUMES,TriWeekly,new Date(2018, 9, 30, 0, 0, 0),
new Date(2019, 0, 31, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2,
new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id);
var triweeklyDistribs = Lambda.array(db.Distribution.manager.search($distributionCycle == triweeklyDistribCycle, false));
assertEquals(triweeklyDistribs.length, 5);
assertEquals(triweeklyDistribs[0].date.toString(), new Date(2018, 9, 30, 13, 0, 0).toString());
assertEquals(triweeklyDistribs[0].end.toString(), new Date(2018, 9, 30, 14, 0, 0).toString());
assertEquals(triweeklyDistribs[1].date.toString(), new Date(2018, 10, 20, 13, 0, 0).toString());
assertEquals(triweeklyDistribs[1].end.toString(), new Date(2018, 10, 20, 14, 0, 0).toString());
assertEquals(triweeklyDistribs[2].date.toString(), new Date(2018, 11, 11, 13, 0, 0).toString());
assertEquals(triweeklyDistribs[2].end.toString(), new Date(2018, 11, 11, 14, 0, 0).toString());
assertEquals(triweeklyDistribs[3].date.toString(), new Date(2019, 0, 1, 13, 0, 0).toString());
assertEquals(triweeklyDistribs[3].end.toString(), new Date(2019, 0, 1, 14, 0, 0).toString());
assertEquals(triweeklyDistribs[4].date.toString(), new Date(2019, 0, 22, 13, 0, 0).toString());
assertEquals(triweeklyDistribs[4].end.toString(), new Date(2019, 0, 22, 14, 0, 0).toString());
service.DistributionService.deleteCycleDistribs(triweeklyDistribCycle);
}
function testDelete() {
//A variable contract with a distribution that has orders
var ordersDistrib = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE;
var ordersDistribId = ordersDistrib.id;
var chicken = TestSuite.CHICKEN;
var order = service.OrderService.make(TestSuite.FRANCOIS, 1, chicken, ordersDistrib.id);
var e = null;
try{
service.DistributionService.delete(ordersDistrib);
}
catch(x:tink.core.Error){
e = x;
}
assertEquals(e.message, "Deletion non possible: some orders are saved for this delivery.");
assertTrue(db.Distribution.manager.get(ordersDistribId) != null);
//A variable contract with a distribution that has no orders
var noOrdersDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE;
var noOrdersDistribId = noOrdersDistrib.id;
var e = null;
try{
service.DistributionService.delete(noOrdersDistrib);
}
catch(x:tink.core.Error){
e = x;
}
assertEquals(e, null);
assertEquals(db.Distribution.manager.get(noOrdersDistribId), null);
//An Amap contract with a distribution that has orders
var amapDistrib = TestSuite.DISTRIB_CONTRAT_AMAP;
var amapDistribId = amapDistrib.id;
var panier = TestSuite.PANIER_AMAP_LEGUMES;
var amapOrder = service.OrderService.make(TestSuite.FRANCOIS, 1, panier, amapDistrib.id);
var e = null;
try{
service.DistributionService.delete(amapDistrib);
}
catch(x:tink.core.Error){
e = x;
}
assertEquals(e, null);
assertEquals(db.Distribution.manager.get(amapDistribId), null);
}
function testUpdateAmapContractOperations(){
var t = sugoi.i18n.Locale.texts;
//Take an amap contract with payments enabled
//Take 2 users and make orders for each
var amapDistrib = TestSuite.DISTRIB_CONTRAT_AMAP;
var contract = amapDistrib.contract;
var panier = TestSuite.PANIER_AMAP_LEGUMES;
var francoisOrder = service.OrderService.make(TestSuite.FRANCOIS, 1, panier, amapDistrib.id);
db.Operation.onOrderConfirm([francoisOrder]);
var sebOrder = service.OrderService.make(TestSuite.SEB, 3, panier, amapDistrib.id);
db.Operation.onOrderConfirm([sebOrder]);
//Check initial operation names and amounts
var francoisOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.FRANCOIS);
assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 1 deliveries");
assertEquals(francoisOperation.amount, -13);
var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB);
assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 1 deliveries");
assertEquals(sebOperation.amount, -39);
//Add a distrib
var distrib = null;
var e = null;
try{
distrib = service.DistributionService.create(contract,new Date(2018, 5, 1, 18, 0, 0),new Date(2018, 5, 1, 18, 30, 0),
amapDistrib.place.id,null,null,null,null,new Date(2018, 4, 1, 18, 0, 0),new Date(2018, 4, 30, 18, 30, 0));
}
catch(x:tink.core.Error){
e = x;
}
//Check names and amounts are modified accordingly
assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries");
assertEquals(francoisOperation.amount, -26);
var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB);
assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries");
assertEquals(sebOperation.amount, -78);
//Add a distrib cycle
var weeklyDistribCycle = service.DistributionService.createCycle(contract,Weekly,new Date(2018, 11, 24, 0, 0, 0),
new Date(2019, 0, 24, 0, 0, 0),new Date(2018, 5, 4, 13, 0, 0),new Date(2018, 5, 4, 14, 0, 0),10,2,
new Date(2018, 5, 4, 8, 0, 0),new Date(2018, 5, 4, 23, 0, 0),TestSuite.PLACE_DU_VILLAGE.id);
//Check names and amounts are modified accordingly
assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 7 deliveries");
assertEquals(francoisOperation.amount, -91);
var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB);
assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 7 deliveries");
assertEquals(sebOperation.amount, -273);
//Delete the distrib cycle
service.DistributionService.deleteCycleDistribs(weeklyDistribCycle);
//Check names and amounts are modified accordingly
assertEquals(francoisOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries");
assertEquals(francoisOperation.amount, -26);
var sebOperation = db.Operation.findCOrderTransactionFor(contract, TestSuite.SEB);
assertEquals(sebOperation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 2 deliveries");
assertEquals(sebOperation.amount, -78);
}
}
-473
View File
@@ -1,473 +0,0 @@
package test;
import Common;
import service.OrderService;
/**
* Test order making, updating and deleting
*
* @author fbarbut
*/
class TestOrders extends haxe.unit.TestCase
{
public function new(){
super();
}
var c : db.Contract;
var p : db.Product;
var bob : db.User;
/**
* get a contract + a user + a product + empty orders
*/
override function setup(){
TestSuite.initDB();
TestSuite.initDatas();
db.Basket.emptyCache();
c = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.contract;
p = TestSuite.STRAWBERRIES;
p.lock();
p.stock = 8;
p.update();
bob = db.User.manager.get(1);
}
/**
Test Basket creation and numbering
**/
public function testBasket(){
var d = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE;
var o = OrderService.make(TestSuite.FRANCOIS, 3, TestSuite.STRAWBERRIES, d.id);
assertEquals(1, o.basket.num);
var o = OrderService.make(TestSuite.SEB, 1, TestSuite.STRAWBERRIES, d.id);
assertEquals(2, o.basket.num);
//order again, should keep existing basket number
var o = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.APPLES, d.id);
assertEquals(1, o.basket.num);
//check bug of 2018-07 : changing the date and place of the distribution leads to lost basket (because basket were indexed on user-date-place)
d.lock();
d.date = new Date(2028,1,1,0,0,0);
var place = new db.Place();
place.name = "Chez Momo";
place.zipCode = "54";
place.amap = d.contract.amap;
place.insert();
d.place = place;
d.update();
//Seb's basket is still 2
var basket = db.Basket.get(TestSuite.SEB,place,d.date);
assertEquals(2, basket.num);
var o = OrderService.make(TestSuite.SEB, 1, TestSuite.APPLES, d.id);
assertEquals(2, o.basket.num);
var o2 = OrderService.edit(o,5,true,null,false);
assertEquals(2, o2.basket.num);
//order to a different distrib in same contract should start a new numbering
var d2 = service.DistributionService.create(d.contract,new Date(2026,6,6,0,0,0),new Date(2026,6,6,1,0,0),place.id,null,null,null,null,new Date(2026,6,4,0,0,0),new Date(2026,6,5,0,0,0));
var o = OrderService.make(TestSuite.SEB, 12, TestSuite.APPLES, d2.id);
assertEquals(1, o.basket.num);
}
/**
* make orders & stock management
*/
public function testStocks(){
var stock = p.stock;
assertTrue(c.type == db.Contract.TYPE_VARORDER);
assertTrue(c.flags.has(db.Contract.ContractFlags.StockManagement));
assertTrue(stock == 8);
//bob orders 3 strawberries, stock fall to 2
//order is update to 6 berries
App.current.eventDispatcher.addOnce(function(e:Event){
switch(e){
case StockMove(e):
assertTrue(e.move==-3);
assertTrue(e.product==p);
default:
}
});
var o = OrderService.make(bob, 3, p, TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id);
assertTrue(p.stock == 5);
assertTrue(o.quantity == 3);
//bob orders 6 more. stock fall to 0, order is reduced to 5
//quantity is not 9 but 8
App.current.eventDispatcher.addOnce(function(e:Event){
switch(e){
case StockMove(e):
assertTrue(e.move==-5);
assertTrue(e.product==p);
default:
}
});
var o = OrderService.make(bob, 6, p, TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id);
assertTrue(p.stock == 0);
assertTrue(o.quantity == 8);
//bob orders again but cant order anything
var o = OrderService.make(bob, 3, p, TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id);
assertTrue(p.stock == 0);
assertTrue(o.quantity == 8);
}
/**
* test edit orders and stock management
*/
function testOrderEdit(){
var o = db.UserContract.manager.select( $user == bob && $product == p, true);
//no order, stock at 8
assertEquals(p.stock , 8);
assertEquals(o , null);
//bob orders 3 strawberries
var o = OrderService.make(bob, 3, p , TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE.id);
assertEquals(o.product.name, p.name);
assertEquals(o.quantity, 3);
assertEquals(p.stock , 5);
//order edit, order 6 berries
App.current.eventDispatcher.addOnce(function(e:Event){
switch(e){
case StockMove(e):
assertTrue(e.move==-3);
assertTrue(e.product==p);
default:
}
});
var o = OrderService.edit(o, 6);
assertTrue(p.stock == 2);
assertTrue(o.quantity == 6);
//order edit, order 9 berries. ( 3 more, but stock fall to 0, reduced to 2 )
App.current.eventDispatcher.addOnce(function(e:Event){
switch(e){
case StockMove(e):
assertEquals( -2.0 , e.move );
assertEquals( p , e.product);
default:
}
});
var o = OrderService.edit(o, 9);
assertEquals(0.0 , p.stock);
assertEquals(8.0 , o.quantity);
//order more, but stock at 0
var o = OrderService.edit(o, 12);
assertEquals(0.0 , p.stock);
assertEquals(8.0 , o.quantity);
//order less
var o = OrderService.edit(o, 6);
assertEquals(2.0 , p.stock);
assertEquals(6.0 , o.quantity);
//floatQt : ordering float quantities should throw an exception
var err = null;
try{
var o = OrderService.edit(o, 6.4);
}catch(e:tink.core.Error){
err = e.message;
}
assertTrue( err!=null );
}
/**
* test orders with multiweight product
*/
function testOrderWithMultiWeightProduct(){
var chicken = TestSuite.CHICKEN;
var distrib = db.Distribution.manager.select($contract == chicken.contract, false);
var order = OrderService.make(bob, 1, chicken, distrib.id);
assertEquals(1.0, order.quantity);
assertEquals(chicken.id, order.product.id);
assertEquals(chicken.price, order.productPrice);
//order 2 more, should not aggregate because multiWeight is true
var order2 = OrderService.make(bob, 2, chicken, distrib.id);
assertTrue(order2.id != order.id);
//we should get 3 different orders
var orders = distrib.getOrders();
//trace(OrderService.prepare(orders));
assertEquals(3, orders.length);
for ( o in orders){
assertEquals(o.user.id, bob.id);
assertEquals(o.product.id, chicken.id);
assertEquals(1.0, o.quantity);
}
}
/**
* @author fbarbut
* @date 2018-01-26
* order a product, edit and set qt to zero, order again.
* the same record should be re-used ( if not multiweight )
*/
function testMakeOrderAndZeroQuantity(){
var fraises = TestSuite.STRAWBERRIES;
var distrib = db.Distribution.manager.select($contract == fraises.contract, false);
var order = OrderService.make(bob, 1, fraises, distrib.id);
order = OrderService.edit(order, 0);
assertEquals(0.0, order.quantity);
var order2 = OrderService.make(bob, 1, fraises, distrib.id);
var bobOrders = [];
for ( o in distrib.getOrders()) if (o.user.id == bob.id) bobOrders.push(o);
assertFalse(fraises.multiWeight);
assertEquals(1, bobOrders.length);
assertEquals(1.0, bobOrders[0].quantity);
}
/**
* Test order deletion and operation deletion in various contexts
@author jbarbic
*/
function testDelete(){
var t = sugoi.i18n.Locale.texts;
//[Test case] Should throw an error when trying to delete order and that the quantity is not zero
var amapDistrib = TestSuite.DISTRIB_CONTRAT_AMAP;
var amapContract = amapDistrib.contract;
var order = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.PANIER_AMAP_LEGUMES, amapDistrib.id);
var orderId = order.id;
db.Operation.onOrderConfirm([order]);
var e1 = null;
try {
service.OrderService.delete(order);
}
catch(x:tink.core.Error){
e1 = x;
}
assertEquals(e1.message, "Deletion not possible: quantity is not zero.");
assertTrue(db.UserContract.manager.get(orderId) != null);
//[Test case] Amap contract and quantity zero with payments disabled
//Check that order is deleted
order = OrderService.edit(order, 0);
var e2 = null;
try {
OrderService.delete(order);
}
catch(x:tink.core.Error){
e2 = x;
}
assertEquals(e2, null);
assertEquals(db.UserContract.manager.get(orderId), null);
//[Test case] Amap contract and quantity zero with payments enabled and 2 orders
//Check that first order is deleted but operation amount is at 0
//Check that operation is deleted only at the second order deletion
var order1 = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.PANIER_AMAP_LEGUMES, amapDistrib.id);
db.Operation.onOrderConfirm([order1]);
var order1Id = order1.id;
order1 = OrderService.edit(order1, 0);
db.Operation.onOrderConfirm([order1]);
var order2 = OrderService.make(TestSuite.FRANCOIS, 1, TestSuite.PANIER_AMAP_LEGUMES, amapDistrib.id);
db.Operation.onOrderConfirm([order2]);
var order2Id = order2.id;
order2 = OrderService.edit(order2, 0);
db.Operation.onOrderConfirm([order2]);
var operation = db.Operation.findCOrderTransactionFor(amapContract, TestSuite.FRANCOIS);
var operationId = operation.id;
var e3 = null;
try {
service.OrderService.delete(order1);
}
catch(x:tink.core.Error){
e3 = x;
}
assertEquals(e3, null);
assertEquals(db.UserContract.manager.get(order1Id), null);
assertTrue(db.Operation.manager.get(operationId) != null);
assertEquals(operation.name, "Contrat AMAP Légumes (La ferme de la Galinette) 1 deliveries");
assertEquals(operation.amount, 0);
var e4 = null;
try {
service.OrderService.delete(order2);
}
catch(x:tink.core.Error){
e4 = x;
}
assertEquals(null, e4);
assertEquals(null, db.UserContract.manager.get(order2Id));
assertEquals(null, db.Operation.manager.get(operationId));
//[Test case] Var Order contract and quantity zero with payments disabled
//Check that order is deleted
var variableDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE;
var g = variableDistrib.contract.amap;
g.lock();
g.flags.unset(HasPayments);
g.update();
var order = OrderService.make(TestSuite.FRANCOIS, 2, TestSuite.STRAWBERRIES, variableDistrib.id);
var orderId = order.id;
db.Operation.onOrderConfirm([order]);
order = OrderService.edit(order, 0);
db.Operation.onOrderConfirm([order]);
var e1 = null;
try {
service.OrderService.delete(order);
}
catch(x:tink.core.Error){
e1 = x;
}
assertEquals(false,variableDistrib.contract.amap.hasPayments() );
assertEquals(null, e1);
assertEquals(null, db.UserContract.manager.get(orderId));
//[Test case] Var Order contract and quantity zero with payments enabled and 2 orders
//Check that first order is deleted
//Check that operation is deleted only at the second order deletion
variableDistrib = TestSuite.DISTRIB_FRUITS_PLACE_DU_VILLAGE;
var variableContract = variableDistrib.contract;
var g = variableDistrib.contract.amap;
g.lock();
g.flags.set(HasPayments);
g.update();
assertTrue(variableContract.amap.hasPayments());
var order1 = OrderService.make(TestSuite.FRANCOIS, 2, TestSuite.STRAWBERRIES, variableDistrib.id);
db.Operation.onOrderConfirm([order1]);
var order1Id = order1.id;
var order2 = OrderService.make(TestSuite.FRANCOIS, 3, TestSuite.APPLES, variableDistrib.id);
db.Operation.onOrderConfirm([order2]);
var order2Id = order2.id;
order1 = OrderService.edit(order1, 0);
db.Operation.onOrderConfirm([order1]);
order2 = OrderService.edit(order2, 0);
db.Operation.onOrderConfirm([order2]);
assertEquals(2, variableContract.getUserOrders(TestSuite.FRANCOIS,variableDistrib).length); //François has 2 orders
var basket = db.Basket.get(TestSuite.FRANCOIS,variableDistrib.place,variableDistrib.date);
assertEquals(2, basket.getOrders().length);
var operation1 = db.Operation.findVOrderTransactionFor(order1.distribution.getKey(), TestSuite.FRANCOIS, variableContract.amap);
var operation1Id = operation1.id;
var operation2 = db.Operation.findVOrderTransactionFor(order2.distribution.getKey(), TestSuite.FRANCOIS, variableContract.amap);
var operation2Id = operation2.id;
assertEquals(operation1Id,operation2Id);
var e2 = null;
try {
//delete strawberries order
service.OrderService.delete(order1);
}
catch(x:tink.core.Error){
e2 = x;
}
assertEquals(null, e2);
assertEquals(null, db.UserContract.manager.get(order1Id) ); //order 1 is deleted
assertTrue( db.Operation.manager.get(operation1Id) != null); //operation should be here
assertEquals(0.0,operation1.amount);
assertEquals(1 , basket.getOrders().length);
var e3 = null;
try {
//delete apple order
service.OrderService.delete(order2);
}
catch(x:tink.core.Error){
e3 = x;
}
assertEquals(null, e3);
assertEquals(null, db.UserContract.manager.get(order2Id)); //order 2 is deleted
assertEquals(null, db.Operation.manager.get(operation1Id)); //operation should be deleted
assertEquals(0 , basket.getOrders().length);
//[Test case] 2 VarOrderContracts and quantity zero with payments enabled and 1 order each
//Check that first order is deleted but operation amount is at 0
//Check that operation is deleted only at the second order deletion
var variableDistrib1 = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE;
var order1 = OrderService.make(TestSuite.FRANCOIS, 2, TestSuite.COURGETTES, variableDistrib1.id);
assertTrue(order1.basket!=null);
// trace("WE GOT A BASKET "+order1.basket.id);
// trace("... THEN RE-GET BASKET user "+TestSuite.FRANCOIS.id+" place "+variableDistrib1.place.id+" date "+variableDistrib1.date);
var basket = db.Basket.get(TestSuite.FRANCOIS,variableDistrib1.place,variableDistrib1.date);
assertTrue(basket!=null);
assertEquals(1, basket.getOrders().length);
db.Operation.onOrderConfirm([order1]);
var order1Id = order1.id;
var variableDistrib2 = TestSuite.DISTRIB_PATISSERIES;
var order2 = OrderService.make(TestSuite.FRANCOIS, 3, TestSuite.FLAN, variableDistrib2.id);
db.Operation.onOrderConfirm([order2]);
var order2Id = order2.id;
order1 = OrderService.edit(order1, 0);
db.Operation.onOrderConfirm([order1]);
order2 = OrderService.edit(order2, 0);
db.Operation.onOrderConfirm([order2]);
//check basket
var basket = db.Basket.get(TestSuite.FRANCOIS,variableDistrib1.place,variableDistrib1.date);
assertEquals(2, basket.getOrders().length);
var operation = db.Operation.findVOrderTransactionFor(order1.distribution.getKey(), TestSuite.FRANCOIS, variableDistrib1.contract.amap);
var operationId = operation.id;
var e4 = null;
try {
service.OrderService.delete(order1);
}
catch(x:tink.core.Error){
e4 = x;
}
assertEquals(e4, null);
assertEquals(db.UserContract.manager.get(order1Id), null);
assertTrue(db.Operation.manager.get(operationId) != null); //op should still be here
assertEquals(0.0,operation.amount);//...with amount 0
var e5 = null;
try {
service.OrderService.delete(order2);
}
catch(x:tink.core.Error){
e5 = x;
}
assertEquals(e5, null);
assertEquals(db.UserContract.manager.get(order2Id), null);
assertEquals(null, db.Operation.manager.get(operationId), null); //op should have been deleted
}
}
-64
View File
@@ -1,64 +0,0 @@
package test;
/**
* Test payments
*
* @author web-wizard
*/
class TestPayments extends haxe.unit.TestCase
{
public function new(){
super();
}
override function setup(){
TestSuite.initDB();
TestSuite.initDatas();
db.Basket.emptyCache();
}
function testValidateDistribution() {
//Take a contract with payments enabled
//Take 2 users and make orders for each
var distrib = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE;
var contract = distrib.contract;
var product = TestSuite.COURGETTES;
var francoisOrder = service.OrderService.make(TestSuite.FRANCOIS, 1, product, distrib.id);
var francoisOrderOperation = db.Operation.onOrderConfirm([francoisOrder]);
var sebOrder = service.OrderService.make(TestSuite.SEB, 3, product, distrib.id);
var sebOrderOperation = db.Operation.onOrderConfirm([sebOrder]);
//They both pay by check
var francoisPayment = db.Operation.makePaymentOperation(TestSuite.FRANCOIS,contract.amap, payment.Check.TYPE, product.price, "Payment by check", francoisOrderOperation[0]);
var sebPayment = db.Operation.makePaymentOperation(TestSuite.SEB,contract.amap, payment.Check.TYPE, 3 * product.price, "Payment by check", sebOrderOperation[0] );
//Autovalidate this old distrib and check that all the payments are validated
service.PaymentService.validateDistribution(distrib);
//distrib should be validated
assertTrue(contract.amap.hasPayments());
assertEquals(true, distrib.validated);
//orders should be marked as paid
assertEquals(true, francoisOrder.paid);
assertEquals(true, sebOrder.paid);
//order operation is not pending
var francoisOperation = db.Operation.findVOrderTransactionFor(francoisOrder.distribution.getKey(), TestSuite.FRANCOIS, contract.amap, false);
var sebOperation = db.Operation.findVOrderTransactionFor(sebOrder.distribution.getKey(), TestSuite.SEB, contract.amap, false);
assertEquals(francoisOperation.pending, false);
assertEquals(sebOperation.pending, false);
//payment operation is not pending
assertEquals(francoisPayment.pending, false);
assertEquals(sebPayment.pending, false);
//basket are validated
var b = db.Basket.get(TestSuite.SEB,distrib.place,distrib.date);
assertEquals(true, b.isValidated());
var b = db.Basket.get(TestSuite.FRANCOIS,distrib.place,distrib.date);
assertEquals(true, b.isValidated());
}
}
-171
View File
@@ -1,171 +0,0 @@
package test;
import Common;
import test.TestSuite;
import service.ReportService;
import service.OrderService;
/**
* Test order reports
*
* @author fbarbut
*/
class TestReports extends haxe.unit.TestCase
{
public function new(){
super();
}
override function setup(){
TestSuite.initDB();
TestSuite.initDatas();
}
function testOrdersByProduct(){
//record orders
var seb = TestSuite.SEB;
var francois = TestSuite.FRANCOIS;
var julie = TestSuite.JULIE;
//distrib de légumes
var d = TestSuite.DISTRIB_LEGUMES_RUE_SAUCISSE;
var carrots = TestSuite.CARROTS;
var courgettes = TestSuite.COURGETTES;
var poulet = TestSuite.CHICKEN;
OrderService.make(seb,4,courgettes,d.id);
OrderService.make(seb,1,poulet,d.id);
OrderService.make(francois,6,courgettes,d.id);
OrderService.make(francois,2,poulet,d.id);
OrderService.make(francois,3,carrots,d.id);
OrderService.make(julie,8,carrots,d.id);
OrderService.make(julie,3,poulet,d.id);
//record orders on ANOTHER distrib
var d2 = service.DistributionService.create(
d.contract,
new Date(2018,2,12,0,0,0),
new Date(2018,2,12,0,3,0),
d.contract.amap.getPlaces().first().id,
null,null,null,null,
new Date(2018,2,8,0,0,0),
new Date(2018,2,11,0,0,0)
);
OrderService.make(julie,6,carrots,d2.id);
OrderService.make(julie,1,poulet,d2.id);
var orders = ReportService.getOrdersByProduct(d);
//courgettes x 10
var courgettesOrder = Lambda.find(orders, function(o) return o.pid==courgettes.id);
assertEquals( 10.0 , courgettesOrder.quantity );
assertEquals( 35.0 , courgettesOrder.totalTTC );
assertEquals( 33.18 , tools.FloatTool.clean(courgettesOrder.totalHT) );
//the report stays the same, even if the product has a new price.
courgettes.lock();
courgettes.price+=4;
courgettes.update();
var orders = ReportService.getOrdersByProduct(d);
var courgettesOrder = Lambda.find(orders, function(o) return o.pid==courgettes.id);
assertEquals( 10.0 , courgettesOrder.quantity );
assertEquals( 35.0 , courgettesOrder.totalTTC );
assertEquals( 33.18 , tools.FloatTool.clean(courgettesOrder.totalHT) );
}
/**
* run once at the beginning
*/
/*override function setup(){
sys.db.Manager.cnx.request("TRUNCATE TABLE UserContract;");
var bubar = db.User.manager.get(1);
var seb = db.User.manager.get(2);
//fruits from group 1
var fraises = db.Product.manager.get(2);
fraises.stock = 30;
var pommes = db.Product.manager.get(3);
var distrib = fraises.contract.getDistribs().first();
db.UserContract.make(bubar, 4, fraises, distrib.id);
db.UserContract.make(seb, 2, pommes, distrib.id);
//vegetables from group 2
var courgettes = db.Product.manager.get(4);
var carottes = db.Product.manager.get(5);
var distrib = courgettes.contract.getDistribs().first();
db.UserContract.make(bubar, 1, carottes ,distrib.id);
db.UserContract.make(seb, 5, courgettes ,distrib.id);
}*/
/**
* test a simple report with just a time frame
*/
/*public function testTimeFrameReport(){
var fraises = db.Product.manager.get(2);
var pommes = db.Product.manager.get(3);
var courgettes = db.Product.manager.get(4);
var carottes = db.Product.manager.get(5);
//check we got the right products
assertEquals("Fraises",fraises.name);
assertEquals("Pommes",pommes.name);
assertEquals("Courgettes",courgettes.name);
assertEquals("Carottes", carottes.name);
var options = { startDate:new Date(2017, 5, 1, 0, 0, 0), endDate:new Date(2017, 5, 31, 0, 0, 0), groups:[], contracts:[] };
var rep = new pro.OrderReport(options);
var data = rep.byProduct();
assertEquals(4,data.length); //should be the 4 products
for ( d in data){
switch(d.pname){
case "Fraises": assertEquals(d.qt, 4);
case "Pommes": assertEquals(d.qt, 2);
case "Carottes": assertEquals(d.qt, 1);
case "Courgettes": assertEquals(d.qt, 5);
}
}
}*/
/**
* test a report with time frame + group
*/
/*public function testGroupReport(){
var options = { startDate:new Date(2017, 5, 1, 0, 0, 0), endDate:new Date(2017, 5, 31, 0, 0, 0), groups:[1], contracts:[] };
var rep = new pro.OrderReport(options);
var data = rep.byProduct();
assertEquals(2,data.length); //should be the 2 products
for ( d in data){
switch(d.pname){
case "Fraises": assertEquals(d.qt, 4);
case "Pommes": assertEquals(d.qt, 2);
}
}
}*/
}
-413
View File
@@ -1,413 +0,0 @@
package test;
import Common;
/**
* CAGETTE.NET TEST SUITE
* @author fbarbut
*/
class TestSuite
{
static function main() {
connectDb();
var r = new haxe.unit.TestRunner();
//Cagette core tests
r.add(new test.TestUser());
r.add(new test.TestOrders());
r.add(new test.TestTools());
r.add(new test.TestDistributions());
r.add(new test.TestPayments());
r.add(new test.TestReports());
#if plugins
//Cagette-pro tests, keep in this order
r.add(new pro.test.TestProductService());
r.add(new pro.test.TestRemoteCatalog());
r.add(new pro.test.TestDistribService());
r.add(new pro.test.TestReports());
//wholesale-order tests
r.add(new who.test.TestWho());
#end
r.run();
}
static function connectDb() {
var dbstr = Sys.args()[0];
var dbreg = ~/([^:]+):\/\/([^:]+):([^@]*?)@([^:]+)(:[0-9]+)?\/(.*?)$/;
if( !dbreg.match(dbstr) )
throw "Configuration requires a valid database attribute, format is : mysql://user:password@host:port/dbname";
var port = dbreg.matched(5);
var dbparams = {
user:dbreg.matched(2),
pass:dbreg.matched(3),
host:dbreg.matched(4),
port:port == null ? 3306 : Std.parseInt(port.substr(1)),
database:dbreg.matched(6),
socket:null
};
sys.db.Manager.cnx = sys.db.Mysql.connect(dbparams);
sys.db.Manager.initialize();
}
public static function initDB(){
//NUKE EVERYTHING BWAAAAH !!
sys.db.Manager.cleanup(); //cleanup cache objects
sql("DROP DATABASE tests;");
sql("CREATE DATABASE tests;");
sql("USE tests;");
var tables : Array<Dynamic> = [
//cagette
db.TxpProduct.manager,
db.TxpCategory.manager,
db.TxpSubCategory.manager,
db.Category.manager,
db.CategoryGroup.manager,
db.ProductCategory.manager,
db.Basket.manager,
db.UserContract.manager,
db.UserAmap.manager,
db.Operation.manager,
db.User.manager,
db.Amap.manager,
db.Contract.manager,
db.Product.manager,
db.Vendor.manager,
db.Place.manager,
db.Distribution.manager,
db.DistributionCycle.manager,
//sugoi tables
sugoi.db.Cache.manager,
sugoi.db.Error.manager,
sugoi.db.File.manager,
sugoi.db.Session.manager,
sugoi.db.Variable.manager,
];
for(t in tables) createTable(t);
#if plugins
//add Cpro datas : we need those tables even in cagette core tests
pro.test.ProTestSuite.initDB();
pro.test.ProTestSuite.initDatas();
#end
}
public static function createTable( m ){
if ( sys.db.TableCreate.exists(m) ){
drop(m);
}
// Sys.println("Creating table "+ m.dbInfos().name);
sys.db.TableCreate.create(m);
}
public static function truncate(m){
sql("TRUNCATE TABLE "+m.dbInfos().name+";");
}
public static function drop(m){
sql("DROP TABLE "+m.dbInfos().name+";");
}
public static function sql(sql){
return sys.db.Manager.cnx.request(sql);
}
//shortcut to datas
public static var FRANCOIS:db.User = null;
public static var SEB:db.User = null;
public static var JULIE:db.User = null;
public static var CHICKEN:db.Product = null;
public static var STRAWBERRIES:db.Product = null;
public static var APPLES:db.Product = null;
public static var AMAP_DU_JARDIN:db.Amap = null;
public static var LOCAVORES:db.Amap = null;
public static var PANIER_AMAP_LEGUMES:db.Product = null;
public static var DISTRIB_CONTRAT_AMAP:db.Distribution = null;
public static var DISTRIB_FRUITS_PLACE_DU_VILLAGE:db.Distribution = null;
public static var DISTRIB_LEGUMES_RUE_SAUCISSE:db.Distribution = null;
public static var CONTRAT_LEGUMES:db.Contract = null;
public static var PLACE_DU_VILLAGE:db.Place = null;
public static var COURGETTES:db.Product = null;
public static var CARROTS:db.Product = null;
public static var FLAN:db.Product = null;
public static var CROISSANT:db.Product = null;
public static var DISTRIB_PATISSERIES:db.Distribution = null;
public static function initDatas(){
//USERS
var f = new db.User();
f.firstName = "François";
f.lastName = "B";
f.email = "francois@alilo.fr";
f.insert();
FRANCOIS = f;
var u = new db.User();
u.firstName = "Seb";
u.lastName = "Z";
u.email = "sebastien@alilo.fr";
u.insert();
SEB = u;
var u = new db.User();
u.firstName = "Julie";
u.lastName = "B";
u.email = "julie@alilo.fr";
u.insert();
JULIE = u;
initApp(u);
//GROUP "AMAP du Jardin public"
var a = new db.Amap();
a.name = "AMAP du Jardin public";
a.contact = f;
a.flags.set(db.Amap.AmapFlags.HasPayments);
a.insert();
AMAP_DU_JARDIN = a;
var place = new db.Place();
place.name = "Place du village";
place.zipCode = "00000";
place.city = "St Martin";
place.amap = a;
place.insert();
PLACE_DU_VILLAGE = place;
//VENDOR "Ferme de la galinette"
var v = new db.Vendor();
v.name = "La ferme de la Galinette";
v.email = "galinette@gmail.com";
v.zipCode = "00000";
v.city = "Bourligheim";
v.insert();
var c = new db.Contract();
c.name = "Contrat AMAP Légumes";
c.startDate = new Date(2017, 1, 1, 0, 0, 0);
c.endDate = new Date(2030, 12, 31, 23, 59, 0);
c.vendor = v;
c.amap = a;
c.type = db.Contract.TYPE_CONSTORDERS;
c.insert();
var p = new db.Product();
p.name = "Panier Légumes";
p.price = 13;
p.contract = c;
p.insert();
PANIER_AMAP_LEGUMES = p;
var d = new db.Distribution();
d.date = new Date(2017, 5, 1, 19, 0, 0);
d.end = new Date(2017, 5, 1, 20, 0, 0);
d.orderStartDate = new Date(2017, 4, 1, 20, 0, 0);
d.orderEndDate = new Date(2017, 4, 30, 20, 0, 0);
d.contract = c;
d.place = place;
d.insert();
DISTRIB_CONTRAT_AMAP = d;
//varying contract for strawberries with stock mgmt
var c = new db.Contract();
c.name = "Commande fruits";
c.vendor = v;
c.startDate = new Date(2017, 1, 1, 0, 0, 0);
c.endDate = new Date(2030, 12, 31, 23, 59, 0);
c.flags.set(db.Contract.ContractFlags.StockManagement);
c.type = db.Contract.TYPE_VARORDER;
c.amap = a;
c.insert();
var p = new db.Product();
p.name = "Fraises";
p.qt = 1;
p.unitType = Common.Unit.Kilogram;
p.price = 10;
p.organic = true;
p.contract = c;
p.stock = 8;
p.insert();
STRAWBERRIES = p;
var p = new db.Product();
p.name = "Pommes";
p.qt = 1;
p.unitType = Common.Unit.Kilogram;
p.price = 6;
p.organic = true;
p.contract = c;
p.stock = 12;
p.insert();
APPLES = p;
var d = new db.Distribution();
d.date = new Date(2017, 5, 1, 19, 0, 0);
d.end = new Date(2017, 5, 1, 20, 0, 0);
d.orderStartDate = new Date(2017, 4, 1, 20, 0, 0);
d.orderEndDate = new Date(2017, 4, 30, 20, 0, 0);
d.contract = c;
d.place = place;
d.insert();
DISTRIB_FRUITS_PLACE_DU_VILLAGE = d;
//second group
var a = new db.Amap();
a.name = "Les Locavores de la Rue Saucisse";
a.contact = f;
a.flags.set(db.Amap.AmapFlags.HasPayments);
a.insert();
LOCAVORES = a;
var place = new db.Place();
place.name = "Rue Saucisse";
place.zipCode = "00000";
place.city = "St Martin";
place.amap = a;
place.insert();
var v = new db.Vendor();
v.name = "La ferme de la courgette enragée";
v.email = "courgette@gmail.com";
v.zipCode = "00000";
v.city = "Bourligeac";
v.insert();
var c = new db.Contract();
c.name = "Commande Legumes";
c.startDate = new Date(2017, 1, 1, 0, 0, 0);
c.endDate = new Date(2030, 12, 31, 23, 59, 0);
c.vendor = v;
c.amap = a;
c.type = db.Contract.TYPE_VARORDER;
c.insert();
CONTRAT_LEGUMES = c;
var p = new db.Product();
p.name = "Courgettes";
p.qt = 1;
p.unitType = Common.Unit.Kilogram;
p.price = 3.5;
p.vat = 5.5;
p.organic = true;
p.contract = c;
p.insert();
COURGETTES = p;
var p = new db.Product();
p.name = "Carottes";
p.qt = 1;
p.unitType = Common.Unit.Kilogram;
p.price = 2.8;
p.vat = 5.5;
p.contract = c;
p.insert();
CARROTS = p;
var p = new db.Product();
p.name = "Poulet";
p.qt = 1.5;
p.unitType = Common.Unit.Kilogram;
p.price = 15;
p.vat = 5.5;
p.multiWeight = true;
p.hasFloatQt = true;
p.contract = c;
p.insert();
CHICKEN = p;
var d = service.DistributionService.create(c,new Date(2017, 5, 1, 19, 0, 0),new Date(2017, 5, 1, 19, 2, 0),place.id,null,null,null,null,new Date(2017, 4, 10, 19, 0, 0),new Date(2017, 4, 20, 19, 0, 0));
DISTRIB_LEGUMES_RUE_SAUCISSE = d;
//PASTRY
var c = new db.Contract();
c.name = "Commande Pâtisseries";
c.startDate = new Date(2017, 1, 1, 0, 0, 0);
c.endDate = new Date(2017, 12, 31, 23, 59, 0);
c.vendor = v;
c.amap = a;
c.type = db.Contract.TYPE_VARORDER;
c.insert();
var p = new db.Product();
p.name = "Flan";
p.qt = 1;
p.unitType = Common.Unit.Kilogram;
p.price = 3.5;
p.organic = true;
p.contract = c;
p.insert();
FLAN = p;
var p = new db.Product();
p.name = "Croissant";
p.qt = 1;
p.unitType = Common.Unit.Kilogram;
p.price = 2.8;
p.contract = c;
p.insert();
CROISSANT = p;
var d = new db.Distribution();
d.date = new Date(2017, 5, 1, 19, 0, 0);
d.contract = c;
d.place = place;
d.insert();
DISTRIB_PATISSERIES = d;
}
static function initApp(u:db.User){
//setup App
var app = App.current = new App();
App.config.DEBUG = true;
app.initLang("en");
app.eventDispatcher = new hxevents.Dispatcher<Event>();
app.plugins = [];
//internal plugins
app.plugins.push(new plugin.Tutorial());
//optionnal plugins
#if plugins
//app.plugins.push( new hosted.HostedPlugIn() );
app.plugins.push( new pro.ProPlugIn() );
app.plugins.push( new connector.ConnectorPlugIn() );
//app.plugins.push( new pro.LemonwayEC() );
app.plugins.push( new who.WhoPlugIn() );
#end
App.current.user = u;
App.current.view = new View();
}
}
-92
View File
@@ -1,92 +0,0 @@
package test;
import Common;
/**
* Test various tools
*
* @author fbarbut
*/
class TestTools extends haxe.unit.TestCase
{
public function new(){
super();
}
function testDateRanges(){
// test last hour range
var now = Date.fromString("2018-01-01 00:30:12");
var r = tools.DateTool.getLastHourRange(now);
assertEquals("2017-12-31 23:00:00",r.from.toString());
assertEquals("2018-01-01 00:00:00",r.to.toString());
// test last minute
var now = Date.fromString("2018-01-01 00:30:12");
var r = tools.DateTool.getLastMinuteRange(now);
assertEquals("2018-01-01 00:29:00",r.from.toString());
assertEquals("2018-01-01 00:30:00",r.to.toString());
}
function testFloatTool(){
assertEquals( true , tools.FloatTool.isEqual(10.0,10.000) );
assertEquals( true , tools.FloatTool.isEqual(10.0,10) );
assertEquals( true , tools.FloatTool.isEqual(10,10) );
assertEquals( true , tools.FloatTool.isEqual(10.00000001,10) );
assertEquals( false , tools.FloatTool.isEqual(10.02,10) );
assertEquals( false , tools.FloatTool.isInt(10.08) );
assertEquals( true , tools.FloatTool.isInt(10.00) );
}
/*
@admin
public function doTests() {
var assertTrue = function(val, ?desc="") {
if (val) {
Sys.println("OK : <br/>");
}else {
Sys.println("ERROR : "+desc+"<br/>");
}
}
//test les fonctions de cotisation
var amap = db.Amap.manager.get(1);
amap.membershipRenewalDate = new Date(2015, 0, 1,0,0,0);
amap.update();
assertTrue(amap.getMembershipYear(new Date(2015, 3, 3, 0, 0, 0) ) == 2015);
assertTrue(amap.getPeriodName(new Date(2015, 3, 3, 0, 0, 0)) == "2015");
assertTrue(amap.getMembershipYear(new Date(2014, 8, 8, 0, 0, 0) ) == 2014);
assertTrue(amap.getPeriodName(new Date(2014, 8, 8, 0, 0, 0) ) == "2014");
assertTrue(amap.getMembershipYear(new Date(2013, 11, 12, 0, 0, 0) ) == 2013);
assertTrue(amap.getPeriodName(new Date(2013, 11, 12, 0, 0, 0) ) == "2013");
amap.membershipRenewalDate = new Date(2015, 8, 1,0,0,0);
amap.update();
assertTrue(amap.getMembershipYear(new Date(2015, 3, 3, 0, 0, 0) ) == 2014);
assertTrue(amap.getPeriodName(new Date(2015, 3, 3, 0, 0, 0)) == "2014-2015");
var d = amap.getMembershipYear(new Date(2015, 8, 8, 0, 0, 0) );
assertTrue( d == 2015, "le 8 sept 2015, on doit etre en cotis 2015, la c " + d);
assertTrue(amap.getPeriodName(new Date(2015, 8, 8, 0, 0, 0)) == "2015-2016");
var d = new Date(2013, 11, 12, 0, 0, 0) ;
assertTrue( amap.getMembershipYear(d) == 2013, "le 12 oct 2013, on doit etre en cotis 2013 , là c " + amap.getMembershipYear(d) );
assertTrue(amap.getPeriodName(d) == "2013-2014", "le 12 oct 2013, on doit etre en 2013-2014 , là c " + amap.getPeriodName(d) );
}*/
}
-48
View File
@@ -1,48 +0,0 @@
package test;
import db.UserAmap;
import Common;
/**
* Test user rights to view contracts
*
* @author web-wizard
*/
class TestUser extends haxe.unit.TestCase
{
public function new(){
super();
}
var contract : db.Contract;
var user : db.User;
var group1 : db.Amap;
var group2 : db.Amap;
var userAmap : db.UserAmap;
/**
* get a contract + a user
*/
override function setup(){
TestSuite.initDB();
TestSuite.initDatas();
contract = db.Contract.manager.get(3);
user = db.User.manager.get(1);
group1 = db.Amap.manager.get(1);
group2 = db.Amap.manager.get(2);
}
/**
* Check that a user who has admin rights for his/her group can't view a contract from a group
he/she doesn't belong to
*/
function testViewContract(){
userAmap = db.UserAmap.getOrCreate(user, group1);
userAmap.giveRight(Right.GroupAdmin);
assertFalse(user.canManageContract(contract));
}
}
-17
View File
@@ -1,17 +0,0 @@
-lib dbadmin
-lib templo
-lib sugoi
-lib hxevents
-lib thx.semver
-lib thx.csv
-lib datetime
-lib hscript
-lib smtpmailer
-lib record-macros
-lib tink_json
-cp common
-cp src
-cp lang/master/tpl
-neko www/tests.n
-main test.TestSuite
-9
View File
@@ -1,9 +0,0 @@
# JS
-js js/test/tests.js
-main test.TestAll
-cp js
-cp common
-lib utest
-lib hxnodejs
-lib sugoi:git:https://github.com/bablukid/sugoi#i18n
-D test
-21
View File
@@ -1,21 +0,0 @@
-lib dbadmin
-lib templo
-lib sugoi
-lib hxevents
-lib thx.semver
-lib thx.csv
-lib datetime
-lib hscript
-lib smtpmailer
-lib record-macros
-lib cagette-pro
-lib cagette-hosted
-lib cagette-wholesale-order
-lib tink_json
-cp common
-cp src
-cp lang/master/tpl
-neko www/tests.n
-D plugins
-main test.TestSuite